1. ホーム
  2. メイヴン

Springbootの部分的なヒント、問題の概要と解決策

2022-02-27 22:18:20
<パス

Collection.containsメソッドを頻繁に呼び出す必要がある場合は、Setを使用します。

// List is faster than set when only insertion is considered
// If you need to use contains frequently to determine existence, set is much faster
List
 list = new ArrayList<>();
Set
 set = new HashSet<>();

//Map gets the key & value to effectively reduce the complexity of the code
HashMap
Ending solution for mybatis-plus 3.4.2 paging failure
3.4.2 is different from 3.4.1. If it is 3,.4.1 you need to do the following configuration
@Configuration
public class MybatisPlusConfiguration {
 
    @Bean
    public PaginationInnerInterceptor paginationInterceptor() {
        return new PaginationInnerInterceptor();
    }
 
}

3.4.2 Do the following configuration
@Configuration(proxyBeanMethods = false)
public class MybatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}

springboot+mybatis-plusmapper not scanning
Add the scan package path to the startup class
@SpringBootApplication(scanBasePackages = "com.order.order02comsumer")
@MapperScan(basePackages = "com.order.order02comsumer.mapper")
public class Order02ComsumerApplication {

    public static void main(String[] args) {
        SpringApplication.run(Order02ComsumerApplication.class, args);
    }

}

Interceptor in springboot does not work with redis
Need to instantiate the interceptor in advance and then use
 @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // Just use the getLoginHandlerInterceptor() method of the instantiated LoginInterceptor
        InterceptorRegistration registration = registry.addInterceptor(getLoginHandlerInterceptor());
        registration.addPathPatterns("/*");
        registration.excludePathPatterns("/login","/login/page");
    }


    /**
     * New out in advance to prevent redis from failing
     * @return
     */
    @Bean
    public LoginIntercepter getLoginHandlerInterceptor(){
        return new LoginIntercepter();
    }

Packed with error: redisFailed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Just remove the pom from the pom.xml file
linux using nohup to start and shutdown
# View the currently running java program
[root@iZwz9j8inmvsbciobnx8ulZ codeGenerator]# ps -aux | grep java
root 24391 7.1 8.7 2962604 156124 ?      Sl 12:09 0:20 java -jar code-web-0.0.1-SNAPSHOT.jar
root 24568 0.0 0.0 112812 968 pts/0 S+ 12:14 0:00 grep --color=auto java
# Kill the program with the specified id
kill -s 9 24391

springboot+mybatis-plus3.4.2 not scanning mapper.xml
Problem description.

1. mapper interface and mepper.xml have the same name
2, the namespace of mapper.xml and the fully qualified class name of the mapper interface are the same
3. configuration file configuration of xml
4. xml file compiled in target
5. xml files are stored in resources->mybatis->mapper The above conditions are all met and it is reasonable that the xml will not be scanned, but it is. So you can make a few changes 1. Modify the pom.xml file (add the following configuration under the build tag)
PS: Today's files and html need to be introduced by folder here, otherwise it will report an error src/main/resources **/*.xml **/*.properties static/** templates/** echarts chart adaption issues /*execute the following code after setOption*/ let chartDom = document.getElementById('newConn'); let newConn = echarts.init(chartDom); let option; option = {......} newConn.setOption(option); window.onresize = newConn.resize; Backend returns missing id precision Create configuration class package com.gj.codeweb.config; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation; import org.springframework.context.annotation; import org.springframework.context.annotation; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; /** * @author 高俊 * @create 2021-11-2021/11/5-14:28 */ @Configuration public class JsonConfig { @Bean @Primary @ConditionalOnMissingBean(ObjectMapper.class) public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) { ObjectMapper objectMapper = builder.createXmlMapper(false).build(); // Global configuration serialization returns JSON processing SimpleModule simpleModule = new SimpleModule(); // JSON Long ==> String simpleModule.addSerializer(Long.class, ToStringSerializer.instance); objectMapper.registerModule(simpleModule); return objectMapper; } } Using annotations in entity classes @JsonSerialize(using = ToStringSerializer.class) com.fasterxml.jackson.core</groupId> jackson-databind</artifactId> 2.12.4</version> compile</scope> </dependency> jq frontend set element distance $("").offset({top:value,left:value)});

entrySet()を繰り返し、Mapのキーと値を取得する。

@Configuration
public class MybatisPlusConfiguration {
 
    @Bean
    public PaginationInnerInterceptor paginationInterceptor() {
        return new PaginationInnerInterceptor();
    }
 
}

@Configuration(proxyBeanMethods = false) public class MybatisPlusConfig { @Bean public MybatisPlusInterceptor mybatisPlusInterceptor(){ MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); return interceptor; } }