分页查询

基于easyui做分页查询功能,的基本步骤:

1 首先我们所创建的用户user对象有属性 id,username。

然后让user继承BaseEntity (包涵下面属性);

private int total = 0;
  // 页码
  private int page = 1;
  // 分页记录数
  private int rows = 10;
  // 开始记录号
  private int start = 0;
  // 结束记录号
  private int end = 0;
  // 是否分页
  private boolean paging = true;

2 持久层 主要注意书写sql语句 :

    (1)这是一个where条件

<sql id="Base_Seach_List">
        <where>
            <if test="userName != null and userName!=''">
                userName like concat('%',#{userName},'%')
            </if>
        </where>
    </sql>

   在这里主要是为了方便查询:例如我们根据前端输入的条件,比如username值为user的数据,让他分页显示出来

这样就可以用到where这个条件了。当然在我们打开页面开始没有输入要查询的条件时候,它不会执行where  sql语句

这样就相当于通过分页显示所有的数据了。

(2)统计符合条件 的数据的个数(当执行where条件时候就只会统计符合查询条件的个数);

<select id="selectCount" parameterType="com.example.demo.entity.User"
        resultType="int">
        select 
        count(1) from user 
        <include refid="Base_Seach_List"/>
    </select>

    (3)查询符合条件的具体的值是什么,通常会返回的是一个集合(同上面一样只会查询到符合前输入条件的。);

<select id="selectList" parameterType="com.example.demo.entity.User"
        resultType="com.example.demo.entity.User">
        select * from user
            <include refid="Base_Seach_List"/>
        order by id asc LIMIT #{start},#{rows}
    </select

3  service层 主要要注意是返回什么样类型的值,比如是对象,还是集合 ,字符串等

同时还要注意都用持久层时候用什么类参数去接受返回的值。当然最主要的还是具体的业务逻辑。

4 controller层 主要是处理前端发送来的请求,还有前端传过来的参数。这里要注意他们是什么格式传送的,是json还是其他格式。

然后调用service层 这个跟service层调用持久层时应该主意的基本相同。

5  至于前端分页显示的用easyui来做会省事很多,不用自己去写分页的js。他们已经封装好了 我们只要在

表单上添加 pagination="true"属性及参数就可以达到分页显示的效果。

posted @ 2017-09-05 20:22  wwqqnn  阅读(348)  评论(0编辑  收藏  举报