Basic steps for paging query function based on easyui:
1 First, the user object we created has attributes id and username.
Then let user inherit BaseEntity (including the following attributes);
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 The persistence layer mainly pays attention to writing sql statements:
(1) This is a where condition
<sql id="Base_Seach_List"> <where> <if test="userName != null and userName!=''"> userName like concat('%',#{userName},'%') </if> </where> </sql>
The main purpose here is to facilitate query: for example, we can display the data in pages according to the conditions input by the front end, such as the username value is user
In this way, the where condition can be used. Of course, when we open the page and do not enter the conditions to be queried, it will not execute the where sql statement
, which is equivalent to displaying all the data through paging.
(2) Count the number of data that meets the conditions (when executing the where condition, only the number that meets the query conditions will be counted);
<select id="selectCount" parameterType="com.example.demo.entity.User" resultType="int"> select count(1) from user <include refid="Base_Seach_List"/> </select>
(3) Query the specific data that meets the conditions What is the value? Usually a collection is returned (same as above, only those that meet the previous input conditions will be queried.);
<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 The service layer should mainly pay attention to what type of value is returned, such as Is it an object, a collection, a string, etc.
At the same time, pay attention to what class parameters are used to receive the returned value when using the persistence layer. Of course, the most important thing is the specific business logic.
4 The controller layer mainly handles requests sent from the front end, as well as parameters passed by the front end. Here you should pay attention to what format they are transmitted in, whether it is json or other formats.
Then call the service layer. This is basically the same idea as when the service layer calls the persistence layer.
5 As for the front-end paging display, it will save a lot of trouble to use easyui, as there is no need to write paging js yourself. They have been encapsulated. We only need to add the pagination="true" attribute and parameters to the
form to achieve the effect of pagination display.
The above is the detailed content of Java implements paging query function based on easyui. For more information, please follow other related articles on the PHP Chinese website!