分离mybatis-plus,实现QueryWrapperUtil,注意该类还需要更多的测试;
This commit is contained in:
parent
574625555b
commit
c9494d8f45
14
pom.xml
14
pom.xml
@ -37,7 +37,6 @@
|
|||||||
<jwt.version>0.9.1</jwt.version>
|
<jwt.version>0.9.1</jwt.version>
|
||||||
<knife4j.version>4.5.0</knife4j.version>
|
<knife4j.version>4.5.0</knife4j.version>
|
||||||
<mybatis-spring-boot.version>3.0.3</mybatis-spring-boot.version>
|
<mybatis-spring-boot.version>3.0.3</mybatis-spring-boot.version>
|
||||||
<mybatis-plus-boot-starter.version>3.5.5</mybatis-plus-boot-starter.version>
|
|
||||||
<mysql.version>8.2.0</mysql.version>
|
<mysql.version>8.2.0</mysql.version>
|
||||||
<jaxb-api.version>2.3.1</jaxb-api.version>
|
<jaxb-api.version>2.3.1</jaxb-api.version>
|
||||||
<jaxb.version>4.0.5</jaxb.version>
|
<jaxb.version>4.0.5</jaxb.version>
|
||||||
@ -65,19 +64,6 @@
|
|||||||
<version>${mybatis-spring-boot.version}</version>
|
<version>${mybatis-spring-boot.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- mybatis-plus 增强CRUD -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.baomidou</groupId>
|
|
||||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.mybatis</groupId>
|
|
||||||
<artifactId>mybatis-spring</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
<version>${mybatis-plus-boot-starter.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- jaxb 处理xml -->
|
<!-- jaxb 处理xml -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.xml.bind</groupId>
|
<groupId>javax.xml.bind</groupId>
|
||||||
|
@ -139,12 +139,6 @@
|
|||||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- mybatis-plus 增强CRUD -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.baomidou</groupId>
|
|
||||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springdoc</groupId>
|
<groupId>org.springdoc</groupId>
|
||||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
|
@ -69,6 +69,11 @@
|
|||||||
<artifactId>ruoyi-system</artifactId>
|
<artifactId>ruoyi-system</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-plugins-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<ruoyi.version>3.8.7.3.4</ruoyi.version>
|
<ruoyi.version>3.8.7.3.4</ruoyi.version>
|
||||||
<ehcache.version>3.10.8</ehcache.version>
|
<ehcache.version>3.10.8</ehcache.version>
|
||||||
|
<mybatis-plus-boot-starter.version>3.5.5</mybatis-plus-boot-starter.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
@ -27,27 +28,40 @@
|
|||||||
<version>${ehcache.version}</version>
|
<version>${ehcache.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- ehcache-->
|
<!-- mybatis-plus 增强CRUD -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.mybatis</groupId>
|
||||||
|
<artifactId>mybatis-spring</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
<version>${mybatis-plus-boot-starter.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- ruoyi-ehcache-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-ehcache</artifactId>
|
<artifactId>ruoyi-ehcache</artifactId>
|
||||||
<version>${ruoyi.version}</version>
|
<version>${ruoyi.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- ehcache-->
|
<!-- mybatis-jpa-->
|
||||||
<dependency>
|
|
||||||
<groupId>com.ruoyi</groupId>
|
|
||||||
<artifactId>ruoyi-ehcache</artifactId>
|
|
||||||
<version>${ruoyi.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- ehcache-->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-mybatis-jpa</artifactId>
|
<artifactId>ruoyi-mybatis-jpa</artifactId>
|
||||||
<version>${ruoyi.version}</version>
|
<version>${ruoyi.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- mybatis-plus-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-mybatis-plus</artifactId>
|
||||||
|
<version>${ruoyi.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- websocket -->
|
<!-- websocket -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
@ -68,6 +82,7 @@
|
|||||||
<modules>
|
<modules>
|
||||||
<module>ruoyi-ehcache</module>
|
<module>ruoyi-ehcache</module>
|
||||||
<module>ruoyi-mybatis-jpa</module>
|
<module>ruoyi-mybatis-jpa</module>
|
||||||
|
<module>ruoyi-mybatis-plus</module>
|
||||||
<module>ruoyi-websocket</module>
|
<module>ruoyi-websocket</module>
|
||||||
<module>ruoyi-plugins-starter</module>
|
<module>ruoyi-plugins-starter</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
<artifactId>ruoyi-mybatis-jpa</artifactId>
|
<artifactId>ruoyi-mybatis-jpa</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-mybatis-plus模块
|
ruoyi-mybatis-jpa
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -22,6 +22,13 @@
|
|||||||
<artifactId>ruoyi-common</artifactId>
|
<artifactId>ruoyi-common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- mybatis-plus 增强CRUD -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -12,6 +12,14 @@ public class BaseColumnInfo {
|
|||||||
protected Query query;
|
protected Query query;
|
||||||
protected String querySql;
|
protected String querySql;
|
||||||
|
|
||||||
|
public Field getField() {
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Query getQuery() {
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
public String getTemplate() {
|
public String getTemplate() {
|
||||||
return getTemplate(false);
|
return getTemplate(false);
|
||||||
}
|
}
|
||||||
|
@ -1,69 +1,84 @@
|
|||||||
// package com.ruoyi.mybatis.utils;
|
package com.ruoyi.mybatis.utils;
|
||||||
|
|
||||||
// import java.util.Arrays;
|
import java.util.ArrayList;
|
||||||
// import java.util.Map;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
// import org.springframework.core.annotation.AnnotationUtils;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.ruoyi.common.core.domain.BaseEntity;
|
||||||
|
import com.ruoyi.mybatis.annotation.Query;
|
||||||
|
import com.ruoyi.mybatis.domain.TableInfo;
|
||||||
|
|
||||||
// import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
public class QueryWrapperUtil {
|
||||||
// import com.ruoyi.common.core.domain.BaseEntity;
|
public static List<String> getArrayFromParam(Object obj) {
|
||||||
// import com.ruoyi.mybatis.annotation.Query;
|
List<String> list = new ArrayList<>();
|
||||||
|
if (obj instanceof String) {
|
||||||
|
for (String split : ((String) obj).split(",")) {
|
||||||
|
list.add(split);
|
||||||
|
}
|
||||||
|
} else if (obj instanceof Collection) {
|
||||||
|
for (Object split : ((Collection<?>) obj)) {
|
||||||
|
list.add(split.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
// public class QueryWrapperUtil {
|
public static <T extends BaseEntity> QueryWrapper<T> initQueryWrapper(T entity) {
|
||||||
// public static <T extends BaseEntity> QueryWrapper<T> initQueryWrapper(T entity) {
|
QueryWrapper<T> queryWrapper = new QueryWrapper<>();
|
||||||
// QueryWrapper<T> queryWrapper = new QueryWrapper<>();
|
TableInfo tableInfo = TableContainer.getTableInfo(entity);
|
||||||
|
Map<String, Object> params = entity.getParams();
|
||||||
|
|
||||||
// Class<?> clazz = entity.getClass();
|
tableInfo.getNotNullColumnsForQuery(entity).stream()
|
||||||
// Map<String, Object> params = entity.getParams();
|
.forEach(field -> {
|
||||||
// Arrays.stream(clazz.getDeclaredFields())
|
Object fieldValue = null;
|
||||||
// .filter(field -> AnnotationUtils.findAnnotation(field, Query.class) != null)
|
try {
|
||||||
// .forEach(field -> {
|
fieldValue = field.getField().get(entity);
|
||||||
// field.setAccessible(true);
|
} catch (IllegalArgumentException e) {
|
||||||
// Query queryAnnotation = field.getAnnotation(Query.class);
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
Query queryAnnotation = field.getQuery();
|
||||||
|
switch (queryAnnotation.operation()) {
|
||||||
|
case eq -> queryWrapper.eq(field.getUnqualifiedColumnName(), fieldValue);
|
||||||
|
case ne -> queryWrapper.ne(field.getUnqualifiedColumnName(), fieldValue);
|
||||||
|
case gt -> queryWrapper.gt(field.getUnqualifiedColumnName(), fieldValue);
|
||||||
|
case ge -> queryWrapper.ge(field.getUnqualifiedColumnName(), fieldValue);
|
||||||
|
case le -> queryWrapper.le(field.getUnqualifiedColumnName(), fieldValue);
|
||||||
|
case lt -> queryWrapper.lt(field.getUnqualifiedColumnName(), fieldValue);
|
||||||
|
case between -> {
|
||||||
|
String begin = queryAnnotation.sections()[0];
|
||||||
|
String end = queryAnnotation.sections()[1];
|
||||||
|
queryWrapper.between(field.getUnqualifiedColumnName(), params.get(begin), params.get(end));
|
||||||
|
}
|
||||||
|
case notBetween -> {
|
||||||
|
String begin = queryAnnotation.sections()[0];
|
||||||
|
String end = queryAnnotation.sections()[1];
|
||||||
|
queryWrapper.notBetween(field.getUnqualifiedColumnName(), params.get(begin),
|
||||||
|
params.get(end));
|
||||||
|
}
|
||||||
|
case like -> queryWrapper.like(field.getUnqualifiedColumnName(), fieldValue);
|
||||||
|
case notLike -> queryWrapper.notLike(field.getUnqualifiedColumnName(), fieldValue);
|
||||||
|
case likeLeft -> queryWrapper.likeLeft(field.getUnqualifiedColumnName(), fieldValue);
|
||||||
|
case likeRight -> queryWrapper.likeRight(field.getUnqualifiedColumnName(), fieldValue);
|
||||||
|
case notLikeLeft -> queryWrapper.notLikeLeft(field.getUnqualifiedColumnName(), fieldValue);
|
||||||
|
case notLikeRight -> queryWrapper.notLikeRight(field.getUnqualifiedColumnName(), fieldValue);
|
||||||
|
case isNull -> queryWrapper.isNull(field.getUnqualifiedColumnName());
|
||||||
|
case isNotNull -> queryWrapper.isNotNull(field.getUnqualifiedColumnName());
|
||||||
|
case in -> queryWrapper.in(field.getUnqualifiedColumnName(),
|
||||||
|
getArrayFromParam(params.get(queryAnnotation.section())));
|
||||||
|
case notIn -> queryWrapper.notIn(field.getUnqualifiedColumnName(),
|
||||||
|
getArrayFromParam(params.get(queryAnnotation.section())));
|
||||||
|
case inSql -> queryWrapper.inSql(field.getUnqualifiedColumnName(), queryAnnotation.sql());
|
||||||
|
case notInSql -> queryWrapper.notInSql(field.getUnqualifiedColumnName(), queryAnnotation.sql());
|
||||||
|
default ->
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Unsupported operation: " + queryAnnotation.operation());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// try {
|
return queryWrapper;
|
||||||
// Object fieldValue = field.get(entity);
|
}
|
||||||
// if (fieldValue != null) { // 判断属性值是否非空
|
}
|
||||||
// switch (queryAnnotation.operation()) {
|
|
||||||
// case eq -> queryWrapper.eq(queryAnnotation.column(), fieldValue);
|
|
||||||
// case ne -> queryWrapper.ne(queryAnnotation.column(), fieldValue);
|
|
||||||
// case gt -> queryWrapper.gt(queryAnnotation.column(), fieldValue);
|
|
||||||
// case ge -> queryWrapper.ge(queryAnnotation.column(), fieldValue);
|
|
||||||
// case le -> queryWrapper.le(queryAnnotation.column(), fieldValue);
|
|
||||||
// case lt -> queryWrapper.lt(queryAnnotation.column(), fieldValue);
|
|
||||||
// case between -> {
|
|
||||||
// String begin = queryAnnotation.section()[0];
|
|
||||||
// String end = queryAnnotation.section()[1];
|
|
||||||
// queryWrapper.between(queryAnnotation.column(), params.get(begin), params.get(end));
|
|
||||||
// }
|
|
||||||
// case notBetween -> {
|
|
||||||
// String begin = queryAnnotation.section()[0];
|
|
||||||
// String end = queryAnnotation.section()[1];
|
|
||||||
// queryWrapper.notBetween(queryAnnotation.column(), params.get(begin),
|
|
||||||
// params.get(end));
|
|
||||||
// }
|
|
||||||
// case like -> queryWrapper.like(queryAnnotation.column(), fieldValue);
|
|
||||||
// case notLike -> queryWrapper.notLike(queryAnnotation.column(), fieldValue);
|
|
||||||
// case likeLeft -> queryWrapper.likeLeft(queryAnnotation.column(), fieldValue);
|
|
||||||
// case likeRight -> queryWrapper.likeRight(queryAnnotation.column(), fieldValue);
|
|
||||||
// case notLikeLeft -> queryWrapper.notLikeLeft(queryAnnotation.column(), fieldValue);
|
|
||||||
// case notLikeRight -> queryWrapper.notLikeRight(queryAnnotation.column(), fieldValue);
|
|
||||||
// case isNull -> queryWrapper.isNull(queryAnnotation.column());
|
|
||||||
// case isNotNull -> queryWrapper.isNotNull(queryAnnotation.column());
|
|
||||||
// case in -> queryWrapper.in(queryAnnotation.column(), (Object[]) fieldValue);
|
|
||||||
// case notIn -> queryWrapper.notIn(queryAnnotation.column(), (Object[]) fieldValue);
|
|
||||||
// case inSql -> queryWrapper.inSql(queryAnnotation.column(), queryAnnotation.sql());
|
|
||||||
// case notInSql -> queryWrapper.notInSql(queryAnnotation.column(), queryAnnotation.sql());
|
|
||||||
// default ->
|
|
||||||
// throw new IllegalArgumentException(
|
|
||||||
// "Unsupported operation: " + queryAnnotation.operation());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } catch (IllegalAccessException e) {
|
|
||||||
// throw new RuntimeException("Failed to access field for building query conditions.", e);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// return queryWrapper;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
33
ruoyi-plugins/ruoyi-mybatis-plus/pom.xml
Normal file
33
ruoyi-plugins/ruoyi-mybatis-plus/pom.xml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>ruoyi-plugins</artifactId>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<version>3.8.7.3.4</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>ruoyi-mybatis-plus</artifactId>
|
||||||
|
|
||||||
|
<description>
|
||||||
|
ruoyi-mybatis-plus模块
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- 通用工具-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- mybatis-plus 增强CRUD -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -1,13 +1,14 @@
|
|||||||
package com.ruoyi.framework.config;
|
package com.ruoyi.mybatisplus.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.DbType;
|
import com.baomidou.mybatisplus.annotation.DbType;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
|
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mybatis Plus 配置
|
* Mybatis Plus 配置
|
@ -39,6 +39,12 @@
|
|||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-mybatis-jpa</artifactId>
|
<artifactId>ruoyi-mybatis-jpa</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- mybatis-plus -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-mybatis-plus</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
Loading…
Reference in New Issue
Block a user