mirror of
https://github.com/chillzhuang/blade-tool
synced 2025-01-11 15:35:38 +08:00
🎉 优化mybatis-plus分页配置
This commit is contained in:
parent
ef31d33f08
commit
f789ef50b5
@ -22,9 +22,11 @@ import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerIntercept
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
|
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springblade.core.boot.props.MybatisPlusProperties;
|
||||||
import org.springblade.core.mp.plugins.SqlLogInterceptor;
|
import org.springblade.core.mp.plugins.SqlLogInterceptor;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
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.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@ -36,6 +38,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@MapperScan("org.springblade.**.mapper.**")
|
@MapperScan("org.springblade.**.mapper.**")
|
||||||
|
@EnableConfigurationProperties(MybatisPlusProperties.class)
|
||||||
public class MybatisPlusConfiguration {
|
public class MybatisPlusConfiguration {
|
||||||
|
|
||||||
private final TenantLineHandler tenantLineHandler;
|
private final TenantLineHandler tenantLineHandler;
|
||||||
@ -45,12 +48,15 @@ public class MybatisPlusConfiguration {
|
|||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(MybatisPlusInterceptor.class)
|
@ConditionalOnMissingBean(MybatisPlusInterceptor.class)
|
||||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
public MybatisPlusInterceptor mybatisPlusInterceptor(MybatisPlusProperties mybatisPlusProperties) {
|
||||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||||
// 配置租户拦截器
|
// 配置租户拦截器
|
||||||
interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(tenantLineHandler));
|
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;
|
return interceptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user