mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
fix select子查询参数问题
This commit is contained in:
parent
468a28f836
commit
c60e89ea79
113
MAPPING.md
113
MAPPING.md
@ -1,113 +0,0 @@
|
||||
# mybatis-plus-join
|
||||
|
||||
#### @EntityMapping 和 @FieldMapping 注解
|
||||
|
||||
UserDO.java
|
||||
|
||||
```java
|
||||
|
||||
@Data
|
||||
@TableName("user")
|
||||
public class UserDO {
|
||||
|
||||
@TableId
|
||||
private Integer id;
|
||||
private Integer pid;//父id
|
||||
/* 其他属性略 */
|
||||
|
||||
/**
|
||||
* 查询上级 一对一
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
@EntityMapping(thisField = "pid", joinField = "id")
|
||||
private UserDO pUser;
|
||||
|
||||
/**
|
||||
* 查询下级 一对多
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
@EntityMapping(thisField = "id", joinField = "pid")
|
||||
private List<UserDO> childUser;
|
||||
|
||||
/**
|
||||
* 带条件的查询下级 一对多
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
@EntityMapping(thisField = "id", joinField = "pid",
|
||||
condition = {
|
||||
@MPJMappingCondition(column = "sex", value = "0"),//sex = '0' 默认条件是等于
|
||||
@MPJMappingCondition(column = "name", value = "张三", keyWord = SqlKeyword.LIKE)//name like '%a%'
|
||||
},
|
||||
apply = @MPJMappingApply(value = "id between 1 and 20"))//拼接sql 同 wrapper.apply()
|
||||
private List<UserDO> childUserCondition;
|
||||
|
||||
/**
|
||||
* 查询地址 (一对多)
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
@EntityMapping(thisField = "id", joinField = "userId")
|
||||
private List<UserAddressDO> addressList;
|
||||
|
||||
/**
|
||||
* 绑定字段 (一对多)
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
@FieldMapping(tag = UserDO.class, thisField = "id", joinField = "pid", select = "id")
|
||||
private List<Integer> childIds;
|
||||
}
|
||||
```
|
||||
|
||||
使用
|
||||
|
||||
```java
|
||||
/**
|
||||
* 一对一,一对多关系映射查询
|
||||
* 如果不需要关系映射就使用mybatis plus原生方法即可,比如 getById listByIds 等
|
||||
* <p>
|
||||
* 注意:关系映射不会去关联查询,而是执行多次单表查询(对结果汇总后使用in语句查询,再对结果进行匹配)
|
||||
*/
|
||||
@SpringBootTest
|
||||
class MappingTest {
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
|
||||
@Test
|
||||
void test1() {
|
||||
UserDO deep = userMapper.selectByIdDeep(2);
|
||||
System.out.println(deep);
|
||||
}
|
||||
|
||||
@Test
|
||||
void test2() {
|
||||
List<UserDO> list = userMapper.selectRelation(mapper -> mapper.selectList(Wrappers.emptyWrapper()));
|
||||
list.forEach(System.out::println);
|
||||
}
|
||||
|
||||
@Test
|
||||
void test3() {
|
||||
Page<UserDO> page = new Page<>(2, 2);
|
||||
Page<UserDO> result = userMapper.selectRelation(mapper -> mapper.selectPage(page, Wrappers.emptyWrapper()));
|
||||
result.getRecords().forEach(System.out::println);
|
||||
}
|
||||
|
||||
/*
|
||||
更多方法请查阅 MPJDeepMapper 或者 MPJDeepService
|
||||
使用方式与 mybatis plus 一致
|
||||
*/
|
||||
}
|
||||
```
|
||||
|
||||
MPJMapping 说明:
|
||||
|
||||
* @EntityMapping / @FieldMapping tag 关联实体类
|
||||
* @EntityMapping / @FieldMapping thisField 当前类关联对应的字段的属性名,可以不填,默认为当前类的主键
|
||||
* @EntityMapping / @FieldMapping joinField 关联类对应的字段的属性名,可以不填,默认为关联类的主键
|
||||
* @EntityMapping / @FieldMapping isThrowExp 一对一查询时,如果查询到多条记录是否抛出异常,true:抛出异常,false:获取列表第一条数据
|
||||
*
|
||||
|
||||
更多功能请看代码注释 [EntityMapping](https://gitee.com/best_handsome/mybatis-plus-join/blob/master/src/main/java/com/github/yulichang/annotation/EntityMapping.java)
|
||||
[FieldMapping](https://gitee.com/best_handsome/mybatis-plus-join/blob/master/src/main/java/com/github/yulichang/annotation/FieldMapping.java)
|
||||
|
||||
|
||||
|
||||
|
@ -24,9 +24,9 @@
|
||||
<img alt="code style" src="https://img.shields.io/badge/license-Apache%202-4EB1BA.svg?style=flat-square">
|
||||
</a>
|
||||
</p>
|
||||
<h1 align="center">mybatis-plus-join</h1>
|
||||
<h1 align="center">MyBatis-Plus-Join</h1>
|
||||
<p align="center">
|
||||
对 <a href="https://gitee.com/baomidou/mybatis-plus" target="_blank">mybatis-plus</a> 多表查询的扩展 |
|
||||
对 <a href="https://gitee.com/baomidou/mybatis-plus" target="_blank">MyBatis-Plus</a> 多表查询的扩展 |
|
||||
<a href="https://gitee.com/best_handsome/mybatis-plus-join-demo" target="_blank">演示工程</a> |
|
||||
<a href="https://www.baidu.com/link?url=wdmhssysW-Mj19Gkcc2CBOzNVoimHat57mlnH78SEU_6y0awYgDKTBy7es9BXnAH&wd=&eqid=908484020001866e000000056440b5e3" target="_blank">使用文档</a> |
|
||||
点个Star支持一下吧 (☆▽☆)
|
||||
@ -59,7 +59,7 @@ QQ群:1022221898 或者
|
||||
```
|
||||
或者clone代码到本地执行 mvn install, 再引入以上依赖
|
||||
<br>
|
||||
注意: mybatis plus version >= 3.3.0
|
||||
注意: MyBatis Plus版本需要3.3.0+
|
||||
<br>
|
||||
|
||||
### 使用
|
||||
|
Loading…
x
Reference in New Issue
Block a user