Home > Java > javaTutorial > Use Struts2 to implement list display and paging function example code

Use Struts2 to implement list display and paging function example code

高洛峰
Release: 2017-03-19 11:08:43
Original
1482 people have browsed it

BlogDAO.java file

/**Return multiple records based on conditions (default all data in one table)*/

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};//代入的参数列表  
    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);//把结果集转成BeanList  
    try {  
        list = qr.query(getConn(), sql, rsh, params);   //调用查询接口的查询函数  
    } catch (SQLException e) {  
        e.printStackTrace();  
    }  
    return list;  
}
Copy after login

BlogActin.java file

private Integer pagenum;//页码  private List<Blog> allblogs;  
//并提供set  get 方法public List<Blog> getAllblogs() {  
    return allblogs;  
}  
public void setAllblogs(List<Blog> allblogs) {  
    this.allblogs = allblogs;  
}  

public Integer getPagenum() {  
    return pagenum;  
}  
public void setPagenum(Integer pagenum) {  
    this.pagenum = pagenum;  
}
Copy after login

----------- ---List method

/** 显示博客列表信息 */   public String alllist() {  
    request=ServletActionContext.getRequest();  
    blogtopic=request.getParameter("blogtopic");  
    allblogs=blogDAO.list(blogtopic, pagenum, 10);  
    num_allblog=blogDAO.countAllNum(blogtopic);  
    num_allblogpage=num_allblog/10+1;  
    return "index";  
}
Copy after login

----------JSPFile

<p class="content">  
    <c:forEach items="${allblogs}" var="allblog">  
        <p class="blog_list">  
        <h1><a href="#" class="category">[${allblog.topic}]</a>  
            <a name="11519817" href="Blog_getContent.action?id=${allblog.id}" target="_blank">${allblog.title}</a></h1>  
        <dl>  
        <dt><a href="#"><img src="img/oyuntaolianwu.jpg" alt="jackyvincefu"></a></dt>  
        <dd><p class="text_length"><pre class="brush:php;toolbar:false">${allblog.content }

           

               C++指针常量               常量指针常量指针常量

           

             

             

                                                                                     
${allblog.writer}                           阅读(${allblog.reader})                           评论(${allblog.discuss})${allblog.time}

           

       

         

    

Copy after login

The above is the detailed content of Use Struts2 to implement list display and paging function example code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template