mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
first
This commit is contained in:
parent
2e22c6b28d
commit
fd51216322
51
README.md
51
README.md
@ -1,10 +1,55 @@
|
|||||||
# mybatis-plus-join
|
# mybatis-plus-join
|
||||||
|
|
||||||
支持连表查询的[mybatis-plus](https://gitee.com/baomidou/mybatis-plus)
|
支持连表查询的[mybatis-plus](https://gitee.com/baomidou/mybatis-plus)
|
||||||
|
|
||||||
## 运行环境
|
## 运行环境
|
||||||
* mysql8
|
|
||||||
* jdk8
|
* mysql8
|
||||||
|
* jdk8
|
||||||
* mybatis-plus 3.4.2
|
* mybatis-plus 3.4.2
|
||||||
|
|
||||||
## 使用方法
|
## 使用方法
|
||||||
* [参考测试类](https://gitee.com/best_handsome/mybatis-plus-join/blob/master/src/test/java/com/example/mp/MpJoinTest.java)
|
|
||||||
|
### 使用
|
||||||
|
|
||||||
|
* entity继承MyBaseEntity
|
||||||
|
* mapper继承MyBaseMapper
|
||||||
|
* service继承MyBaseService
|
||||||
|
* serviceImpl继承MyBaseServiceImpl
|
||||||
|
|
||||||
|
### MyLambdaQueryWrapper用法
|
||||||
|
|
||||||
|
#### select(UserEntity::getId) 查询指定的字段,支持可变参数
|
||||||
|
|
||||||
|
查询user表中的head_img,name和user_address表中的address,tel
|
||||||
|

|
||||||
|
对应sql
|
||||||
|

|
||||||
|
|
||||||
|
#### selectAll(UserEntity.class) 查询UserEntity全部字段
|
||||||
|
|
||||||
|
查询user全部字段和user_address表中的address,tel
|
||||||
|

|
||||||
|
对应sql
|
||||||
|

|
||||||
|
|
||||||
|
#### as(UserEntity::getHeadImg,UserDTO::getUserHeadImg)
|
||||||
|
|
||||||
|
查询字段head_img as userHeadImg
|
||||||
|

|
||||||
|
对应sql
|
||||||
|

|
||||||
|
|
||||||
|
#### 左连接 leftJoin(UserEntity::getId,UserAddressEntity::getUserId,right -> right)
|
||||||
|
|
||||||
|
前连个参数是两个表的连接条件 -> user left join user_address on user.id = User_address.user_id
|
||||||
|
第三个参数是右表wrapper对象,可以继续使用,以上方法.
|
||||||
|
|
||||||
|
#### 条件查询eq()
|
||||||
|
|
||||||
|

|
||||||
|
对应sql
|
||||||
|

|
||||||
|
|
||||||
|
#### [参考测试类](https://gitee.com/best_handsome/mybatis-plus-join/blob/master/src/test/java/com/example/mp/MpJoinTest.java)
|
||||||
|
|
||||||
|
BIN
doc/selectAs.png
Normal file
BIN
doc/selectAs.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
doc/selectAsSql.png
Normal file
BIN
doc/selectAsSql.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
@ -12,6 +12,8 @@ public class UserDTO {
|
|||||||
private String sex;
|
private String sex;
|
||||||
/** user */
|
/** user */
|
||||||
private String headImg;
|
private String headImg;
|
||||||
|
/** user */
|
||||||
|
private String userHeadImg;//同 headImg 别名测试
|
||||||
/** user_address */
|
/** user_address */
|
||||||
private String tel;
|
private String tel;
|
||||||
/** user_address */
|
/** user_address */
|
||||||
|
@ -111,9 +111,9 @@ public class MyJoinLambdaQueryWrapper<T extends MyBaseEntity> extends MyAbstract
|
|||||||
setEntityClass(clazz);
|
setEntityClass(clazz);
|
||||||
TableInfo info = TableInfoHelper.getTableInfo(getEntityClass());
|
TableInfo info = TableInfoHelper.getTableInfo(getEntityClass());
|
||||||
info.getFieldList().forEach(s ->
|
info.getFieldList().forEach(s ->
|
||||||
selectColumnList.add(new SelectColumn(this.rUid, s.getColumn(), s.getColumn()/*s.getProperty()*/, null)));
|
selectColumnList.add(new SelectColumn(this.rUid, s.getColumn(), null, null)));
|
||||||
if (StringUtils.isNotBlank(info.getKeyColumn())) {
|
if (StringUtils.isNotBlank(info.getKeyColumn())) {
|
||||||
selectColumnList.add(new SelectColumn(this.rUid, info.getKeyColumn(),info.getKeyColumn()/* info.getKeyProperty()*/, null));
|
selectColumnList.add(new SelectColumn(this.rUid, info.getKeyColumn(), null, null));
|
||||||
}
|
}
|
||||||
return typedThis;
|
return typedThis;
|
||||||
}
|
}
|
||||||
|
@ -119,9 +119,14 @@ class MpJoinTest {
|
|||||||
* <p>
|
* <p>
|
||||||
* 自己去探索发现吧!
|
* 自己去探索发现吧!
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("all")
|
||||||
@Test
|
@Test
|
||||||
void test4() {
|
void test4() {
|
||||||
//todo
|
userMapper.selectJoinList(new MyLambdaQueryWrapper<UserEntity>()
|
||||||
|
.as(UserEntity::getHeadImg,UserDTO::getUserHeadImg)
|
||||||
|
.leftJoin(UserEntity::getId, UserAddressEntity::getUserId,
|
||||||
|
right -> right.select(UserAddressEntity::getAddress, UserAddressEntity::getTel))
|
||||||
|
, UserDTO.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user