🎉 优化mybatis-plus分页配置

This commit is contained in:
smallchill 2021-01-20 17:01:11 +08:00
parent ef31d33f08
commit f789ef50b5
2 changed files with 48 additions and 2 deletions

View File

@ -22,9 +22,11 @@ import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerIntercept
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
import lombok.AllArgsConstructor;
import org.mybatis.spring.annotation.MapperScan;
import org.springblade.core.boot.props.MybatisPlusProperties;
import org.springblade.core.mp.plugins.SqlLogInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -36,6 +38,7 @@ import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
@AllArgsConstructor
@MapperScan("org.springblade.**.mapper.**")
@EnableConfigurationProperties(MybatisPlusProperties.class)
public class MybatisPlusConfiguration {
private final TenantLineHandler tenantLineHandler;
@ -45,12 +48,15 @@ public class MybatisPlusConfiguration {
*/
@Bean
@ConditionalOnMissingBean(MybatisPlusInterceptor.class)
public MybatisPlusInterceptor mybatisPlusInterceptor() {
public MybatisPlusInterceptor mybatisPlusInterceptor(MybatisPlusProperties mybatisPlusProperties) {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// 配置租户拦截器
interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(tenantLineHandler));
// 配置分页拦截器
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
paginationInnerInterceptor.setMaxLimit(mybatisPlusProperties.getPageLimit());
paginationInnerInterceptor.setOverflow(mybatisPlusProperties.getOverflow());
interceptor.addInnerInterceptor(paginationInnerInterceptor);
return interceptor;
}

View File

@ -0,0 +1,40 @@
/**
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springblade.core.boot.props;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* MybatisPlus配置类
*
* @author Chill
*/
@Data
@ConfigurationProperties(prefix = "blade.mybatis-plus")
public class MybatisPlusProperties {
/**
* 分页最大数
*/
private Long pageLimit = 500L;
/**
* 溢出总页数后是否进行处理
*/
protected Boolean overflow = false;
}