Use Struts2 for list display and paging

Source: Internet
Author: User

The following is the paging function of a project in the previous two days. BlogDAO. the java file [java]/** returns multiple records based on the condition (all data in a table by default) */public List <Blog> list (String kw, Integer pageCur, Integer pageSize) {List <Blog> list = null; Integer limitaInteger = (pageCur-1) * pageSize; Integer limitbInteger = pageCur * pageSize; Object [] params = {limitaInteger, limitbInteger }; // input parameter list String sqlWhere = ""; String SQL = "select * from csdn_blog where first = 1"; if (kw! = Null &&! Kw. equals ("") {sqlWhere = "and topic like '%" + kw + "%'";} SQL + = sqlWhere; SQL + = "order by id desc limit ?,? "; ResultSetHandler <List <Blog> rsh = new BeanListHandler <Blog> (Blog. class); // convert the result set to BeanList try {list = qr. query (getConn (), SQL, rsh, params); // call the query function of the query interface} catch (SQLException e) {e. printStackTrace ();} return list;} blogmgmt. java file [java] private Integer pagenum; // page number [java] view plaincopyprivate List <Blog> allblogs; and provides the set get method [java] public List <Blog> getAllblogs () {return allblogs;} pu Blic void setAllblogs (List <Blog> allblogs) {this. allblogs = allblogs;} [java] public Integer getPagenum () {return pagenum;} public void setPagenum (Integer pagenum) {this. pagenum = pagenum;} list method [java]/** display blog list information */public String alllist () {request = ServletActionContext. getRequest (); blogtopic = request. getParameter ("blogtopic"); allblogs = blogDAO. list (blogtopic, pagenum, 10); num_allblog = blog DAO. countAllNum (blogtopic); num_allblogpage = num_allblog/10 + 1; return "index";} JSP file [html] <div class = "content"> <c: forEach items = "$ {allblogs}" var = "allblog"> <div class = "blog_list">

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.