mybatis配置文件
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package org.nl.config.mybatis;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@EnableTransactionManagement
|
||||
@Configuration
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
/**
|
||||
* 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除)
|
||||
添加自增插件
|
||||
*/
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
// 分页插件
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
//乐观锁插件
|
||||
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
|
||||
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,14 +41,16 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, Dict> impleme
|
||||
public IPage<Dict> queryAll(Map whereJson, PageQuery page) {
|
||||
String blurry = null;
|
||||
if (ObjectUtil.isNotEmpty(whereJson.get("blurry"))) blurry = whereJson.get("blurry").toString();
|
||||
IPage<Dict> pages = this.page(new Page<>(page.getPage() + 1, page.getSize()), new QueryWrapper<Dict>()
|
||||
.select("MAX(dict_id) AS dictId, code, name")
|
||||
IPage<Dict> pages = new Page<>(page.getPage() + 1, page.getSize());
|
||||
QueryWrapper<Dict> lam = new QueryWrapper<>();
|
||||
lam.select("MAX(dict_id) AS dictId, code, name")
|
||||
.lambda()
|
||||
.like(ObjectUtil.isNotEmpty(blurry), Dict::getCode, blurry)
|
||||
.or(ObjectUtil.isNotEmpty(blurry))
|
||||
.like(ObjectUtil.isNotEmpty(blurry), Dict::getName, blurry)
|
||||
.orderBy(true, true, Dict::getCode)
|
||||
.groupBy(Dict::getCode, Dict::getName));
|
||||
.orderBy(true, true, Dict::getCode)
|
||||
.groupBy(Dict::getCode, Dict::getName);
|
||||
sysDictMapper.selectPage(pages, lam);
|
||||
return pages;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user