use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project drug by xiabud.
the class MybatisPlusConfig method paginationInterceptor.
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor page = new PaginationInterceptor();
page.setDialectType("mysql");
return page;
}
use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project loc-framework by lord-of-code.
the class LocMybatisAutoConfiguration method createSqlSessionFactory.
@Nullable
private SqlSessionFactory createSqlSessionFactory(ConfigurableListableBeanFactory configurableListableBeanFactory, String prefixName, MybatisProperties mybatisProperties) {
DataSource dataSource = configurableListableBeanFactory.getBean(prefixName + "Ds", DataSource.class);
MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
sqlSessionFactoryBean.setVfs(LocSpringBootVFS.class);
Optional.ofNullable(mybatisProperties.getConfigLocation()).map(this.resourceLoader::getResource).ifPresent(sqlSessionFactoryBean::setConfigLocation);
org.apache.ibatis.session.Configuration configuration = mybatisProperties.getConfiguration();
if (configuration == null && !StringUtils.hasText(mybatisProperties.getConfigLocation())) {
configuration = new org.apache.ibatis.session.Configuration();
}
sqlSessionFactoryBean.setConfiguration(configuration);
Optional.ofNullable(mybatisProperties.getConfigurationProperties()).ifPresent(sqlSessionFactoryBean::setConfigurationProperties);
Optional.ofNullable(mybatisProperties.getTypeAliasesPackage()).ifPresent(sqlSessionFactoryBean::setTypeAliasesPackage);
Optional.ofNullable(mybatisProperties.getTypeHandlersPackage()).ifPresent(sqlSessionFactoryBean::setTypeHandlersPackage);
if (!ObjectUtils.isEmpty(mybatisProperties.resolveMapperLocations())) {
sqlSessionFactoryBean.setMapperLocations(mybatisProperties.resolveMapperLocations());
}
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
sqlSessionFactoryBean.setPlugins(new Interceptor[] { paginationInterceptor });
try {
SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBean.getObject();
if (sqlSessionFactory == null) {
log.error("sqlSessionFactoryBean get object is null");
return null;
}
register(configurableListableBeanFactory, sqlSessionFactory, prefixName + "SessionFactory", prefixName + "Sf");
if (!Strings.isNullOrEmpty(mybatisProperties.getBasePackage())) {
createBasePackageScanner((BeanDefinitionRegistry) configurableListableBeanFactory, mybatisProperties.getBasePackage(), prefixName);
} else {
createClassPathMapperScanner((BeanDefinitionRegistry) configurableListableBeanFactory, prefixName);
}
return sqlSessionFactory;
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return null;
}
use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project personManage by WHUTdk.
the class MybatisPlusConfig method paginationInterceptor.
/**
* 分页插件
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
paginationInterceptor.setDialectType("mysql");
return paginationInterceptor;
}
use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project javaBook-src by huifer.
the class MybatisPlusConfig method paginationInterceptor.
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
// 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求 默认false
// paginationInterceptor.setOverflow(false);
// 设置最大单页限制数量,默认 500 条,-1 不受限制
// paginationInterceptor.setLimit(500);
// 开启 count 的 join 优化,只针对部分 left join
paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));
return paginationInterceptor;
}
use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project dynamic_dataSource by tianliuzhen.
the class MybatisPlusConfig method paginationInterceptor.
/* @Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
// 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求 默认false
// paginationInterceptor.setOverflow(false);
// 设置最大单页限制数量,默认 500 条,-1 不受限制
// paginationInterceptor.setLimit(500);
List<ISqlParser> sqlParserList = new ArrayList<>();
// 如果设置了全局逻辑删除、这里会失效,设置局部没关系已经测试
// 攻击 SQL 阻断解析器、加入解析链
sqlParserList.add(new BlockAttackSqlParser() {
@Override
public void processDelete(Delete delete) {
// 如果你想自定义做点什么,可以重写父类方法像这样子
if ("user_test".equals(delete.getTable().getName())) {
// 自定义跳过某个表,其他关联表可以调用 delete.getTables() 判断
log.info("跳过表:"+"user_test(这个表允许全部删除)");
return ;
}
super.processDelete(delete);
}
});
paginationInterceptor.setSqlParserList(sqlParserList);
return paginationInterceptor;
}*/
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
/**
* 1、【测试攻击 SQL】 阻断解析器、加入解析链
* 自定义设置参考上面注释
*/
List<ISqlParser> sqlParserList = new ArrayList<>();
sqlParserList.add(new BlockAttackSqlParser());
/**
* 2、【测试多租户】 SQL 解析处理拦截器<br>
* 传入的值一般都是配置文件 静态变量或者session中取出
* 意思就是在你的所有的sql 加一个条件 即是 where AND user.manager_id = 0
*/
TenantSqlParser tenantSqlParser = new TenantSqlParser();
tenantSqlParser.setTenantHandler(new TenantHandler() {
@Override
public Expression getTenantId(boolean where) {
// 此判断用于支持返回多个租户 ID 场景,具体使用查看示例工程
return new LongValue(0L);
}
@Override
public String getTenantIdColumn() {
// 多租户自定义字段
return "manager_id";
}
@Override
public boolean doTableFilter(String tableName) {
/*
if ("user".equals(tableName)) {
return true;
}*/
return false;
}
});
sqlParserList.add(tenantSqlParser);
paginationInterceptor.setSqlParserList(sqlParserList);
paginationInterceptor.setSqlParserFilter(new ISqlParserFilter() {
@Override
public boolean doFilter(MetaObject metaObject) {
MappedStatement ms = SqlParserHelper.getMappedStatement(metaObject);
// 意思允许 UserMapper下的这个 getAll 不用加 AND user.manager_id = 0
if ("com.aaa.mybatisplus.mapper.UserMapper.getAll".equals(ms.getId())) {
return true;
}
return false;
}
});
return paginationInterceptor;
}
Aggregations