mybatisplus分页查询问题

osc_47904062 发布于 05/12 16:16
阅读 708
收藏 0

开源之夏第三届火热来袭,高校学生参与赢万元奖金!>>>

@TableName("t_dept")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Dept {
    @TableId
    private Integer id;
    private String name;
    private String userCount;
    private List<Employee> emps;
}
public interface DeptMapper extends BaseMapper<Dept> {
    public IPage<Dept> getPage3(Page<Dept> deptIPage);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.study.mapper.DeptMapper">
    <select id="getPage3" resultMap="resMap2">
        SELECT d.id as id,d.name as name,
        e.id AS e_id ,e.name AS e_name,e.dept_id as e_deptId
        FROM t_dept d JOIN t_employee e ON d.id = e.dept_id
    </select>
    <resultMap id="resMap2" type="com.study.bean.Dept">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="user_count" property="userCount"/>
        <collection property="emps" ofType="Employee">
            <id column="e_id" property="id"/>
            <result column="e_name" property="name"/>
            <result column="e_deptId" property="deptId"/>
        </collection>
    </resultMap>
</mapper>
@RunWith(SpringRunner.class)
@SpringBootTest
public class MybatisTest {

    @Autowired
    DeptMapper deptMapper;
    @Test
    public void testPage4(){
        Page<Dept> page = new Page<>();
        page.setSize(3);
        page.setCurrent(1);
        IPage<Dept> page3 = deptMapper.getPage3(page);
        System.out.println(JSONUtil.toJsonStr(page3));
    }
}
mysql> SELECT d.id as id,d.name as name,
        e.id AS e_id ,e.name AS e_name,e.dept_id as e_deptId
        FROM t_dept d JOIN t_employee e ON d.id = e.dept_id;
+----+----------+------+--------+----------+
| id | name     | e_id | e_name | e_deptId |
+----+----------+------+--------+----------+
|  1 | 开发部   |    1 | 石头1  |        1 |
|  1 | 开发部   |    2 | 石头2  |        1 |
|  2 | 测试部门 |    3 | 石头3  |        2 |
|  2 | 测试部门 |    4 | 石头4  |        2 |
+----+----------+------+--------+----------+

以前在mybatis中是可以合并这个数据的,不知道mybatisplus为什么不可以了。

 

 

加载中
0
ducat7
ducat7
<collection property="emps" ofType="Employee">

请把这句的“Employee”类全路径,写全了才认。

OSCHINA
登录后可查看更多优质内容
返回顶部
顶部
返回顶部
顶部