⬆️ Upgrading dependencies. 升级 mybatis-plus 3.4.1 支持插件主体配置设置 https://gitee.com/log4j/pig/issues/I24QAB

This commit is contained in:
lifenow 2020-11-11 14:36:25 +08:00
parent f42db4eaaf
commit 2f35983fa1
5 changed files with 40 additions and 51 deletions

View File

@ -17,16 +17,13 @@
package com.pig4cloud.pig.common.core.config; package com.pig4cloud.pig.common.core.config;
import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DatePattern;
import com.pig4cloud.pig.common.core.mybatis.SqlFilterArgumentResolver;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry; import org.springframework.format.FormatterRegistry;
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar; import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.List;
import static org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type.SERVLET; import static org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type.SERVLET;
@ -40,11 +37,6 @@ import static org.springframework.boot.autoconfigure.condition.ConditionalOnWebA
@ConditionalOnWebApplication(type = SERVLET) @ConditionalOnWebApplication(type = SERVLET)
public class WebMvcConfiguration implements WebMvcConfigurer { public class WebMvcConfiguration implements WebMvcConfigurer {
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(new SqlFilterArgumentResolver());
}
/** /**
* 增加GET请求参数中时间类型转换 {@link com.pig4cloud.pig.common.core.jackson.PigJavaTimeModule} * 增加GET请求参数中时间类型转换 {@link com.pig4cloud.pig.common.core.jackson.PigJavaTimeModule}
* <ul> * <ul>

View File

@ -1,36 +0,0 @@
package com.pig4cloud.pig.common.core.mybatis;
import cn.hutool.core.util.StrUtil;
import org.junit.Test;
/**
* @author lengleng
* @date 2020/10/12
*/
public class SqlFilterArgumentResolverTest {
@Test
public void supportsParameter() {
}
@Test
public void resolveArgument() {
String param = "delete create_time";
System.out.println(clear(param));
}
private String clear(String param) {
if (StrUtil.isBlank(param)) {
return StrUtil.trim(param);
}
StringBuilder builder = new StringBuilder();
for (int i = 0; i < param.length(); i++) {
char c = param.charAt(i);
if (Character.isJavaIdentifierPart(c)) {
builder.append(c);
}
}
return builder.toString();
}
}

View File

@ -31,6 +31,12 @@
<dependencies> <dependencies>
<!--hutool-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-core</artifactId>
<version>${hutool.version}</version>
</dependency>
<!--mybatis--> <!--mybatis-->
<dependency> <dependency>
<groupId>com.baomidou</groupId> <groupId>com.baomidou</groupId>
@ -42,5 +48,15 @@
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
</dependency> </dependency>
<!--server-api-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -16,9 +16,16 @@
package com.pig4cloud.pig.common.mybatis; package com.pig4cloud.pig.common.mybatis;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.pig4cloud.pig.common.mybatis.resolver.SqlFilterArgumentResolver;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
/** /**
* @author lengleng * @author lengleng
@ -27,15 +34,25 @@ import org.springframework.context.annotation.Configuration;
* mybatis plus 统一配置 * mybatis plus 统一配置
*/ */
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
public class MybatisAutoConfiguration { public class MybatisAutoConfiguration implements WebMvcConfigurer {
/** /**
* 分页插件 * SQL 过滤器避免SQL 注入
* @return PaginationInterceptor * @param argumentResolvers
*/
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(new SqlFilterArgumentResolver());
}
/**
* 分页插件, 对于单一数据库类型来说,都建议配置该值,避免每次分页都去抓取数据库类型
*/ */
@Bean @Bean
public PaginationInterceptor paginationInterceptor() { public MybatisPlusInterceptor mybatisPlusInterceptor() {
return new PaginationInterceptor(); MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
} }
} }

View File

@ -16,7 +16,7 @@
* *
*/ */
package com.pig4cloud.pig.common.core.mybatis; package com.pig4cloud.pig.common.mybatis.resolver;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.baomidou.mybatisplus.core.metadata.OrderItem;