Springmvc + mybatis + mysql + ajax implement Paging

Source: Internet
Author: User

Springmvc + mybatis + mysql + ajax implement Paging
Paging is the most common requirement in web applications. The following is a complete paging process. 1.html page content: leave an area for the page, for example: <! -- Page number -->

<Div id = "page_list" class = "page_list clearfix"> <p class = "page" id = "page"> <! -- Dynamically display page content --> </p> </div>

 

2. js Code: The courseName, loadCourseByPage, addCourse, and deleteCourse in the Code are all in the project logic and can be ignored.
Var pageNum = 1; // The default value is the first page of var courseName = ""; // the variables in the project, which can be ignored. // when the page is loaded, the first page of data is loaded. $ (function () {loadCourseByPage (1, courseName) ;}); // load the Content function loadCourseByPage (page, courseName) {$. ajax ({url: path + "customCourse/course", type: "POST", data: {"pageNum": page, "courseName": courseName}, success: function (data) {var pageMsg = data. pageMsg; var courses = data. courses; $ (". ques_class_list "). Empty (); // clear the original data $ (". page "). empty (); if (courses. length = 0 | courses = null) {$ (". ques_class_list "). html ("<div style = 'text-align: center; '> 

 

3. java paging information entity class: pageMsg
Package com.tar ena. tots. entity; import java. util. arrayList; import java. util. list;/*** stores paging-related information ** @ author tarena **/public class PageMsg {// The requested page number private Integer pageNum = 1; // The length of each page is private Integer pageSize = 5; // the total number of private Integer totalPage; // set of corresponding data. This item cannot be used in jsp (bound with model ), however, private List <Object> objects = new ArrayList <Object> (); public PageMsg () {super ();} public PageMsg (Integer pageNum, integer pageSize) {super (); this. pageNum = pageNum; this. pageSize = pageSize;} public Integer getBegin () {return (pageNum-1) * pageSize;} public Integer getPageNum () {return pageNum;} public void setPageNum (Integer pageNum) {this. pageNum = pageNum;} public Integer getPageSize () {return pageSize;} public void setPageSize (Integer pageSize) {this. pageSize = pageSize;} public Integer getTotalPage () {return totalPage;} public void setTotalPage (Integer totalPage) {this. totalPage = totalPage;} public List <Object> getObjects () {return objects;} public void setObjects (List <Object> objects) {this. objects = objects;} @ Override public String toString () {return "PageMsg [objects =" + objects + ", pageNum =" + pageNum + ", pageSize = "+ pageSize +", totalPage = "+ totalPage +"] ";}}

 

4. The last content in mapper is: <! -- Query the question bank by page -->
<select id="findAllCourseByPage" parameterType="map"resultType="com.tarena.tots.entity.Course">select * from course<where><if test="courseName != null and courseName != ''">courseName = #{courseName}</if>and userId = #{userId} and isDel = 0</where>limit #{pageMsg.begin},#{pageMsg.pageSize}</select>

 

This is a complete paging process.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.