MyBatis-Plus完成链表分页查询

1.1.编写dao接口方法

public interface StudentDao extends BaseMapper<Student> {
    IPage<Student> selectPageWithClazz(IPage<Student> page, @Param("ew") Wrapper<Student> queryWrapper);


}

2.编写mapper映射文件的内容

    <resultMap id="student" type="com.wzy.entity.Student" autoMapping="true">
        <id property="id" column="id"/>
        <result property="clazzId" column="clazz_id"/>
        <association property="clazz" javaType="com.wzy.entity.Clazz" autoMapping="true">
            <id property="cid" column="cid"/>
            <result property="clazzName" column="clazz_name"/>
        </association>
    </resultMap>


    <select id="selectPageWithClazz" resultMap="student">
        select * from student  s join clazz c on s.clazz_id=c.cid
        <if test="ew!=null and ew.customSqlSegment!=null">
            ${ew.customSqlSegment}
        </if>
    </select>

3.测试

@Autowired
    private StudentDao studentDao;
    //联表分页条件查询
    @Test
    public void testSelectPageWithDept(){
        IPage<Student> iPage=new Page(1,2);
        QueryWrapper<Sthdent> wrapper=new QueryWrapper<>();
        IPage<Student> sIPage = studentDao.selectPageWithDept(iPage, wrapper);
 
        System.out.println("总页码:"+sIPage.getPages());
        System.out.println("总条数:"+sIPage.getTotal());
        System.out.println("当前页的记录:");
        List<Student> records = sIPage.getRecords();
        for(Student s:records){
            System.out.println("姓名:"+s.getName()+";薪水:"+s.getSalary()+";所在部门名称:"+s.getDept().getDname());
        }
    }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值