初始化仓库
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package xtools.boot.db.mybatisplus;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
import xtools.boot.core.utils.ModuleLoadUtils;
|
||||
import xtools.boot.db.mybatisplus.selector.BootDbMybatisPlusImportSelector;
|
||||
|
||||
/**
|
||||
* <p>Title : BootCacheRedisConfiguration</p>
|
||||
* <p>Description : BootCacheRedisConfiguration</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/01/01 09:30
|
||||
*/
|
||||
@Import(BootDbMybatisPlusImportSelector.class)
|
||||
public class BootDbMybatisPlusConfiguration {
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*/
|
||||
public BootDbMybatisPlusConfiguration() {
|
||||
ModuleLoadUtils.loadSuccess(BootDbMybatisPlusConfiguration.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package xtools.boot.db.mybatisplus.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* <p>Title : MybatisPlusConfig</p>
|
||||
* <p>Description : MybatisPlusConfig</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/1/5 10:15
|
||||
*/
|
||||
@Configuration
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
/**
|
||||
* 配置 MybatisPlus 拦截器
|
||||
*
|
||||
* @return MybatisPlus 拦截器
|
||||
*/
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
// 添加分页插件
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
return interceptor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package xtools.boot.db.mybatisplus.selector;
|
||||
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
|
||||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
/**
|
||||
* <p>Title : BootDbMybatisPlusImportSelector</p>
|
||||
* <p>Description : BootDbMybatisPlusImportSelector</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/01/01 09:30
|
||||
*/
|
||||
public class BootDbMybatisPlusImportSelector implements ImportBeanDefinitionRegistrar {
|
||||
|
||||
/**
|
||||
* 根据给定的注释元数据,根据需要注册bean
|
||||
*
|
||||
* @param importingClassMetadata AnnotationMetadata
|
||||
* @param registry BeanDefinitionRegistry
|
||||
*/
|
||||
@Override
|
||||
public void registerBeanDefinitions(@NonNull AnnotationMetadata importingClassMetadata, @NonNull BeanDefinitionRegistry registry) {
|
||||
// 构建扫描对象
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(registry, true);
|
||||
// 扫描包下路径
|
||||
scanner.scan("xtools.boot.db.mybatisplus");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package xtools.boot.db.mybatisplus.utils;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import xtools.base.config.BaseParams;
|
||||
import xtools.core.ArrUtils;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>Title : QueryUtils</p>
|
||||
* <p>Description : QueryUtils</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/1/17 19:16
|
||||
*/
|
||||
public class QueryUtils implements BaseParams {
|
||||
|
||||
/**
|
||||
* 添加时间范围查询
|
||||
*
|
||||
* @param query 查询条件
|
||||
* @param timeRange 时间范围
|
||||
* @param timeField 时间字段
|
||||
* @param <T> 泛型
|
||||
*/
|
||||
public static <T> void addTimeRange(LambdaQueryWrapper<T> query, Instant[] timeRange, SFunction<T, ?> timeField) {
|
||||
if (ArrUtils.isEmpty(timeRange) || timeRange.length != CP_NUM2) {
|
||||
return;
|
||||
}
|
||||
query.ge(Objects.nonNull(timeRange[CP_NUM0]), timeField, timeRange[CP_NUM0]);
|
||||
query.le(Objects.nonNull(timeRange[CP_NUM1]), timeField, timeRange[CP_NUM1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分页条件
|
||||
*
|
||||
* @param currentPage 当前页
|
||||
* @param pageSize 页面大小
|
||||
* @param <T> 泛型
|
||||
* @return 分页条件
|
||||
*/
|
||||
public static <T> Page<T> getPage(Integer currentPage, Integer pageSize) {
|
||||
if (Objects.isNull(currentPage) || currentPage < CP_NUM1) {
|
||||
currentPage = CP_NUM1;
|
||||
}
|
||||
if (Objects.isNull(pageSize) || pageSize < CP_NUM1) {
|
||||
pageSize = CP_NUM10;
|
||||
}
|
||||
return new Page<>(currentPage, pageSize);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
xtools.boot.db.mybatisplus.BootDbMybatisPlusConfiguration
|
||||
Reference in New Issue
Block a user