mybatisplus分页讲解

collection和association的使用方法

1. 关联-association
2.集合-collection

用collection的一对多

public class User{

private Card card_one;

private List<Card> card_many;

}

用association的一对一

public class Card implements Serializable{
 private Integer id;
 private String code;
//省略set和get方法.
}
public class Person implements Serializable{
 private Integer id;
 private String name;
 private String sex;
 private Integer age;
 //人和身份证是一对一的关系
 private Card card;
//省略set/get方法.
}

分页三层结构写法

封装类

@Data
@NoArgsConstructor
@AllArgsConstructor
public class RolesPathVo {
    private Integer id;
    private String name;
    private String link;
}

entity层

public class Roles implements Serializable {
    @ApiModelProperty(value = "id")
    private Integer id;
    @ApiModelProperty(value = "名字")
    private String name;
    @ApiModelProperty(value = "言论")
    private String remark;
    @ApiModelProperty(value = "状态")
    private Integer status;

    private List<Menus> menus;
}

mapper层

    List<RolesPathVo> findRoles(@Param("start") Integer start, @Param("limit") Integer limit);

service层

   List<RolesPathVo> findRoles(Integer page,Integer pageSize);

impl层

   @Override
    public List<RolesPathVo> findRoles(Integer page, Integer pageSize) {
        Integer start = (page - 1) * pageSize;
        Integer limit = pageSize;
        return rolesMapper.findRoles(start,limit);
    }

.xml文件

<?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.systop.tanzhen.mapper.RolesMapper">
    <resultMap id="selectRolesPath1" type="com.systop.tanzhen.entity.Roles">
        <id property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <collection property="menus" ofType="com.systop.tanzhen.entity.Menus">
            <result property="link" column="link"/>
        </collection>
    </resultMap>
    <!-- 查询用户列表-->
    <select id="findRoles" resultType="com.systop.tanzhen.vo.RolesPathVo">
        SELECT `roles`.`id`,`roles`.`name`,`menus`.`link`  FROM `role_menu` LEFT JOIN `menus` ON `menus`.`id`=`role_menu`.`menu_id` JOIN `roles` ON `role_menu`.`role_id`=`roles`.`id`
        <if test="start != null and limit != null">
            limit #{start}, #{limit}
        </if>
    </select>

</mapper>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值