This commit is contained in:
bjdys 2021-08-24 10:56:42 +08:00
parent 214260ff99
commit e77710a8a5

View File

@ -86,53 +86,35 @@ public class UserDO {
* 映射只对以Deep结尾比如 getByIdDeep listByIdsDeep 等 * 映射只对以Deep结尾比如 getByIdDeep listByIdsDeep 等
* 如果不需要关系映射就使用mybatis plus原生方法即可比如 getById listByIds 等 * 如果不需要关系映射就使用mybatis plus原生方法即可比如 getById listByIds 等
* *
* @see com.github.yulichang.base.service.MPJDeepService * 注意关系映射不会去关联查询而是执行多次单表查询使用in语句查询后对结果进行匹配
*/ */
@SpringBootTest @SpringBootTest
class MappingTest { class MappingTest {
@Resource @Resource
private UserMapper userMapper; private UserMapper userMapper;
/**
* 根据id查询
* <p>
* 查询过程:
* 一共查询了3次
* 第一次查询目标UserDO
* 第二次根据pid查询上级用户
* 第三次根据自身id查询下级用户
*/
@Test @Test
void test1() { void test1() {
UserDO deep = userMapper.selectByIdDeep(2); UserDO deep = userMapper.selectByIdDeep(2);
System.out.println(deep); System.out.println(deep);
} }
/**
* 查询全部
* <p>
* 查询过程:
* 一共查询了3次
* 第一次查询目标UserDO集合
* 第二次根据pid查询上级用户不会一条记录一条记录的去查询对pid进行汇总用in语句一次性查出来然后进行匹配
* 第三次根据自身id查询下级用户不会一条记录一条记录的去查询对id进行汇总用in语句一次性查出来然后进行匹配
*/
@Test @Test
void test2() { void test2() {
List<UserDO> list = userMapper.selectListDeep(Wrappers.emptyWrapper()); List<UserDO> list = userMapper.selectListDeep(Wrappers.emptyWrapper());
list.forEach(System.out::println); list.forEach(System.out::println);
} }
/**
* 分页查询
* <p>
* 查询过程与上面一致
*/
@Test @Test
void test3() { void test3() {
Page<UserDO> page = userMapper.selectPageDeep(new Page<>(2, 2), Wrappers.emptyWrapper()); Page<UserDO> page = userMapper.selectPageDeep(new Page<>(2, 2), Wrappers.emptyWrapper());
page.getRecords().forEach(System.out::println); page.getRecords().forEach(System.out::println);
} }
/**
* 跟多方法请查阅 MPJDeepMapper 或者 MPJDeepService
* 使用方式与 mybatis plus 一致
*/
} }
``` ```