mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
添加泛型约束 升级 mybatis plus 版本
This commit is contained in:
parent
e1a8930a31
commit
c0001f3a90
12
README.md
12
README.md
@ -1,9 +1,8 @@
|
||||
# mybatis-plus-join
|
||||
|
||||
* 支持连表查询的 [mybatis-plus](https://gitee.com/baomidou/mybatis-plus)
|
||||
* 对 [mybatis-plus](https://gitee.com/baomidou/mybatis-plus) 多表查询的扩展
|
||||
* [演示工程](https://gitee.com/best_handsome/mybatis-plus-join-demo)
|
||||
* 点个Star支持一下吧 :)
|
||||
* [一对一,一对多](https://gitee.com/best_handsome/mybatis-plus-join/blob/master/MAPPING.md)
|
||||
|
||||
QQ群:1022221898
|
||||
|
||||
@ -34,9 +33,7 @@ QQ群:1022221898
|
||||
* service继承MPJBaseService (可选)
|
||||
* serviceImpl继承MPJBaseServiceImpl (可选)
|
||||
|
||||
## 核心类 MPJLambdaWrapper和MPJQueryWrapper
|
||||
|
||||
### MPJLambdaWrapper用法
|
||||
### Lambda形式用法(MPJLambdaWrapper)
|
||||
|
||||
#### 简单的三表查询
|
||||
|
||||
@ -97,7 +94,8 @@ WHERE (
|
||||
* 默认主表别名是t,其他的表别名以先后调用的顺序使用t1,t2,t3....
|
||||
* 条件查询,可以查询主表以及参与连接的所有表的字段,全部调用mp原生的方法,正常使用没有sql注入风险
|
||||
|
||||
MPJLambdaWrapper其他功能
|
||||
MPJLambdaWrapper其他功能
|
||||
|
||||
* [简单的SQL函数使用](https://gitee.com/best_handsome/mybatis-plus-join/wikis/selectFunc()?sort_id=4082479)
|
||||
* [ON语句多条件支持](https://gitee.com/best_handsome/mybatis-plus-join/wikis/leftJoin?sort_id=3496671)
|
||||
|
||||
@ -140,7 +138,7 @@ FROM
|
||||
LIMIT ?,?
|
||||
```
|
||||
|
||||
### MPJQueryWrapper
|
||||
### String形式用法(MPJQueryWrapper)
|
||||
|
||||
#### 简单的3表查询
|
||||
|
||||
|
5
pom.xml
5
pom.xml
@ -11,7 +11,7 @@
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
@ -37,10 +37,11 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!--suppress VulnerableLibrariesLocal -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<version>3.5.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -21,7 +21,7 @@ public interface MPJJoinMapper<T> extends BaseMapper<T> {
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
Integer selectJoinCount(@Param(Constants.WRAPPER) MPJBaseJoin wrapper);
|
||||
Integer selectJoinCount(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回一条记录
|
||||
@ -30,14 +30,14 @@ public interface MPJJoinMapper<T> extends BaseMapper<T> {
|
||||
* @param clazz resultType
|
||||
*/
|
||||
<DTO> DTO selectJoinOne(@Param(Constant.CLAZZ) Class<DTO> clazz,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin wrapper);
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回Map
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
Map<String, Object> selectJoinMap(@Param(Constants.WRAPPER) MPJBaseJoin wrapper);
|
||||
Map<String, Object> selectJoinMap(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回记录集合
|
||||
@ -46,14 +46,14 @@ public interface MPJJoinMapper<T> extends BaseMapper<T> {
|
||||
* @param clazz resultType
|
||||
*/
|
||||
<DTO> List<DTO> selectJoinList(@Param(Constant.CLAZZ) Class<DTO> clazz,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin wrapper);
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回Map集合
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
List<Map<String, Object>> selectJoinMaps(@Param(Constants.WRAPPER) MPJBaseJoin wrapper);
|
||||
List<Map<String, Object>> selectJoinMaps(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回记录集合并分页
|
||||
@ -64,7 +64,7 @@ public interface MPJJoinMapper<T> extends BaseMapper<T> {
|
||||
*/
|
||||
<DTO, P extends IPage<?>> IPage<DTO> selectJoinPage(P page,
|
||||
@Param(Constant.CLAZZ) Class<DTO> clazz,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin wrapper);
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回Map集合并分页
|
||||
@ -72,5 +72,5 @@ public interface MPJJoinMapper<T> extends BaseMapper<T> {
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
<P extends IPage<?>> IPage<Map<String, Object>> selectJoinMapsPage(P page,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin wrapper);
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
}
|
||||
|
@ -18,49 +18,50 @@ public interface MPJJoinService<T> extends IService<T> {
|
||||
/**
|
||||
* 根据 Wrapper 条件,查询总记录数
|
||||
*/
|
||||
default Integer selectJoinCount(MPJBaseJoin wrapper) {
|
||||
default Integer selectJoinCount(MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinCount(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回一条记录
|
||||
*/
|
||||
default <DTO> DTO selectJoinOne(Class<DTO> clazz, MPJBaseJoin wrapper) {
|
||||
default <DTO> DTO selectJoinOne(Class<DTO> clazz, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinOne(clazz, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回集合
|
||||
*/
|
||||
default <DTO> List<DTO> selectJoinList(Class<DTO> clazz, MPJBaseJoin wrapper) {
|
||||
default <DTO> List<DTO> selectJoinList(Class<DTO> clazz, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinList(clazz, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回集合并分页
|
||||
*/
|
||||
default <DTO, P extends IPage<?>> IPage<DTO> selectJoinListPage(P page, Class<DTO> clazz, MPJBaseJoin wrapper) {
|
||||
default <DTO, P extends IPage<?>> IPage<DTO> selectJoinListPage(P page, Class<DTO> clazz, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinPage(page, clazz, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回Map
|
||||
*/
|
||||
default Map<String, Object> selectJoinMap(MPJBaseJoin wrapper) {
|
||||
default Map<String, Object> selectJoinMap(MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinMap(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回Map集合
|
||||
*/
|
||||
default List<Map<String, Object>> selectJoinMaps(MPJBaseJoin wrapper) {
|
||||
default List<Map<String, Object>> selectJoinMaps(MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinMaps(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回Map集合并分页
|
||||
*/
|
||||
default <P extends IPage<Map<String, Object>>> IPage<Map<String, Object>> selectJoinMapsPage(P page, MPJBaseJoin wrapper) {
|
||||
default <P extends IPage<Map<String, Object>>> IPage<Map<String, Object>> selectJoinMapsPage(
|
||||
P page, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinMapsPage(page, wrapper);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.MPJTableMapperHelper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
/**
|
||||
@ -13,10 +14,11 @@ import org.springframework.core.annotation.Order;
|
||||
* @author yulichang
|
||||
* @since 1.2.0
|
||||
*/
|
||||
@Order(Integer.MIN_VALUE)
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public class MappingConfig implements ApplicationListener<ApplicationReadyEvent> {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullableProblems")
|
||||
public void onApplicationEvent(ApplicationReadyEvent event) {
|
||||
TableInfoHelper.getTableInfos().forEach(i ->
|
||||
MPJTableInfoHelper.initTableInfo(i.getEntityType(), MPJTableMapperHelper.get(i.getEntityType())));
|
||||
|
@ -29,6 +29,7 @@ import com.github.yulichang.method.mp.SelectPage;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.core.GenericTypeResolver;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -44,7 +45,7 @@ import static java.util.stream.Collectors.toList;
|
||||
* @author yulichang
|
||||
* @see DefaultSqlInjector
|
||||
*/
|
||||
@Order(Integer.MIN_VALUE)
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
@ConditionalOnMissingBean({DefaultSqlInjector.class, AbstractSqlInjector.class, ISqlInjector.class})
|
||||
public class MPJSqlInjector extends DefaultSqlInjector {
|
||||
|
||||
|
@ -3,5 +3,6 @@ package com.github.yulichang.interfaces;
|
||||
/**
|
||||
* @author yulichang
|
||||
*/
|
||||
public interface MPJBaseJoin {
|
||||
@SuppressWarnings("unused")
|
||||
public interface MPJBaseJoin<T> {
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ import java.util.stream.Collectors;
|
||||
@Deprecated
|
||||
@SuppressWarnings("unused")
|
||||
public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambdaQueryWrapper<T>>
|
||||
implements Query<MPJLambdaQueryWrapper<T>, T, SFunction<T, ?>>, MPJJoin<MPJLambdaQueryWrapper<T>> {
|
||||
implements Query<MPJLambdaQueryWrapper<T>, T, SFunction<T, ?>>, MPJJoin<MPJLambdaQueryWrapper<T>, T> {
|
||||
|
||||
/**
|
||||
* 查询字段
|
||||
|
@ -29,7 +29,7 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapper<T>>
|
||||
implements Query<MPJQueryWrapper<T>, T, String>, MPJJoin<MPJQueryWrapper<T>> {
|
||||
implements Query<MPJQueryWrapper<T>, T, String>, MPJJoin<MPJQueryWrapper<T>, T> {
|
||||
|
||||
/**
|
||||
* 查询字段
|
||||
|
@ -7,7 +7,7 @@ import com.github.yulichang.toolkit.Constant;
|
||||
* @author yulichang
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface MPJJoin<Children> extends MPJBaseJoin {
|
||||
public interface MPJJoin<Children, T> extends MPJBaseJoin<T> {
|
||||
|
||||
default Children leftJoin(String joinSql) {
|
||||
return leftJoin(true, joinSql);
|
||||
|
@ -7,7 +7,6 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.query.MPJQueryWrapper;
|
||||
import com.github.yulichang.toolkit.Constant;
|
||||
import com.github.yulichang.toolkit.LambdaUtils;
|
||||
import com.github.yulichang.toolkit.MPJWrappers;
|
||||
@ -37,7 +36,7 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWrapper<T>>
|
||||
implements Query<MPJLambdaWrapper<T>>, LambdaJoin<MPJLambdaWrapper<T>> {
|
||||
implements Query<MPJLambdaWrapper<T>>, LambdaJoin<MPJLambdaWrapper<T>, T> {
|
||||
|
||||
/**
|
||||
* 查询字段 sql
|
||||
|
@ -9,7 +9,7 @@ import com.github.yulichang.wrapper.interfaces.on.OnFunction;
|
||||
* @author yulichang
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface LambdaJoin<Children> extends MPJBaseJoin {
|
||||
public interface LambdaJoin<Children, Entity> extends MPJBaseJoin<Entity> {
|
||||
|
||||
/**
|
||||
* left join
|
||||
|
Loading…
x
Reference in New Issue
Block a user