关于mybatis分页:

	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("indexpic:indexPic:indexPic")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<IndexPicDO> indexPicList = indexPicService.list(query);
		int total = indexPicService.count(query);
		PageUtils pageUtils = new PageUtils(indexPicList, total);
		return pageUtils;
	}


	public Query(Map<String, Object> params) {
		this.putAll(params);
		// 分页参数
		this.offset = Integer.parseInt(params.get("offset").toString());
		this.limit = Integer.parseInt(params.get("limit").toString());
		this.put("offset", offset);
		this.put("page", offset / limit + 1);
		this.put("limit", limit);
	}
	<select id="list" resultType="com.bootdo.indexpic.domain.IndexPicDO">
		select `cid`,`title`,`content`,`pic`,`status`,`type`,`created`,`gtm_create` from a_index_pic

        <where>  
		  		  <if test="cid != null and cid != ''"> and cid = #{cid} </if>
		  		  <if test="title != null and title != ''"> and title = #{title} </if>
		  		  <if test="content != null and content != ''"> and content = #{content} </if>
		  		  <if test="pic != null and pic != ''"> and pic = #{pic} </if>
		  		  <if test="status != null and status != ''"> and status = #{status} </if>
		  		  <if test="type != null and type != ''"> and type = #{type} </if>
		  		  <if test="created != null and created != ''"> and created = #{created} </if>
		  		  <if test="gtmCreate != null and gtmCreate != ''"> and gtm_create = #{gtmCreate} </if>
		  		</where>
        <choose>
            <when test="sort != null and sort.trim() != ''">
                order by ${sort} ${order}
            </when>
			<otherwise>
                order by cid desc
			</otherwise>
        </choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值