当前位置 博文首页 > u011767319的博客:Mybatis Plus的使用个人笔记
<!--mybatis-plus start-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.1.0</version>
</dependency>
<!-- mybatis-plus自动模板引擎依赖 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.1.0</version>
</dependency>
<!-- mybatis-plus需要的模板引擎freemarker -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>
<!--mybatis-plus end-->
mybatis-plus:
configuration:
#配置返回数据库(column下划线命名&&返回java实体是驼峰命名),自动匹配无需as(没开启这个,SQL需要写as: select user_id as userId)
map-underscore-to-camel-case: true
cache-enabled: false
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #打印sql语句,调试用
/**
* 分页插件
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
/**
* 格式化打印 sql
*/
@Bean
public PerformanceInterceptor performanceInterceptor() {
PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
//格式化sql语句
Properties properties = new Properties();
properties.setProperty("format", "true");
performanceInterceptor.setProperties(properties);
return performanceInterceptor;
}
由于在mybatis框架的xml中<= , >=解析会出现问题,编译报错,所以需要转译
第一种写法:
原符号 < <= > >= & ’ "
替换符号 < <= > >= & ' "
详细表:
原符号 | 替换符号 |
---|---|
< | < |
<= | <= |
>= | >= |
& | & |
’ | ' |
" | " |
例如:sql如下:
unix_timestamp(target.mc_end_date)<= unix_timestamp(#{MonthEndTime});unix_timestamp(target.mc_start_date) >= unix_timestamp(#{MonthBeginTime})
第二种写法:
大于等于
<![CDATA[ >= ]]>
小于等于
<![CDATA[ <= ]]>
例如:sql如下:
mc_end_date <![CDATA[ >= ]]> #{endTime} and mc_start_date <![CDATA[ <= ]]> #{startTime}
cs