分页插件后端书写

1.参数封装

 
 
package com.ziku.ms.youle.web.util;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 查询参数
 */
public class Query extends LinkedHashMap<String, Object> {
   private static final long serialVersionUID = 1L;
   // 
   private int offset;
   // 每页条数
   private int limit;
   
   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);
   }

   public int getOffset() {
      return offset;
   }

   public void setOffset(int offset) {
      this.put("offset", offset);
   }

   public int getLimit() {
      return limit;
   }

   public void setLimit(int limit) {
      this.limit = limit;
   }
}
2.分页工具类进行分页
 
 
package com.ziku.ms.youle.web.util;

import java.io.Serializable;
import java.util.List;

public class  PageUtils implements Serializable {
   private static final long serialVersionUID = 1L;
   private int total;
   private List<?> rows;

   public PageUtils(List<?> list, int total) {
      this.rows = list;
      this.total = total;
   }

   public int getTotal() {
      return total;
   }

   public void setTotal(int total) {
      this.total = total;
   }

   public List<?> getRows() {
      return rows;
   }

   public void setRows(List<?> rows) {
      this.rows = rows;
   }

}
3.sql书写
 
 
查询参数
<select id="getWxUser" parameterType="hashmap" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
   from ems_wx_channel_user
   WHERE
   subscribe = 'yes'
   <if test="channelId != null and channelId != ''">
       and channel_id=#{channelId}
   </if>
   <if test="nickName != null and nickName != ''">
       and nick_name like CONCAT('%',#{nickName},'%')
   </if>
   <if test="province != null and province != ''">
       and province like CONCAT('%',#{province},'%')
   </if>
   <if test="memo != null and memo != ''">
       and memo like CONCAT('%',#{memo},'%')
   </if>
   <if test="subscribeSource != null and subscribeSource != ''">
      AND subscribe_source = #{subscribeSource}
   </if>
   ORDER BY
   subscribe_time DESC
   <if test="offset != null and limit != null">
      limit #{offset}, #{limit}
   </if>
</select>
查询总数
<select id="getWxUserCount" parameterType="hashmap" resultType="java.lang.Integer">
   select
   count(1)
    from ems_wx_channel_user
      WHERE
      subscribe = 'yes'
      <if test="channelId != null and channelId != ''">
        and channel_id=#{channelId}
      </if>
      <if test="nickName != null and nickName != ''">
        and nick_name like CONCAT('%',#{nickName},'%')
      </if>
      <if test="province != null and province != ''">
        and province like CONCAT('%',#{province},'%')
      </if>
      <if test="memo != null and memo != ''">
        and memo like CONCAT('%',#{memo},'%')
      </if>
      <if test="subscribeSource != null and subscribeSource != ''">
         AND subscribe_source = #{subscribeSource}
      </if>
      ORDER BY
      subscribe_time DESC
   </select>


猜你喜欢

转载自blog.csdn.net/heihei_100/article/details/80689619