请教spingmvc分页问题

yschat2012 2014-12-27 02:06:07
写了下面几个文件
InfoDao.java
import com.java1234.model.Info;

public class InfoDao {

	public ArrayList<Info> getInfoList(Connection con,String sql)throws Exception{
ArrayList<Info> infoList=new ArrayList<Info>();
PreparedStatement pstmt=con.prepareStatement(sql);
ResultSet rs=pstmt.executeQuery();
while(rs.next()){
Info info=new Info();
info.setId(rs.getInt("id"));
info.setTypeId(rs.getInt("typeId"));
info.setTitle(rs.getString("title"));
info.setContent(rs.getString("content"));

infoList.add(info);
}
return infoList;
}

}


Info.java
public class Info {

private int id;
private int typeId;
private String title;
private String content;


public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public int getTypeId() {
return typeId;
}

public void setTypeId(int typeId) {
this.typeId = typeId;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

}

StudentController.java
@Controller
@RequestMapping("/student")
public class StudentController {
private InfoDao infoDao=new InfoDao();


@RequestMapping("/list")
public ModelAndView list() throws Exception{
DbUtil dbutil = new DbUtil();
Connection con =dbutil.getCon();
String sql="select * from tb_info order by infodate desc";
ArrayList<Info> infoList=infoDao.getInfoList(con, sql);

ModelAndView mav=new ModelAndView();
mav.addObject("studentList", infoList);
mav.setViewName("pages/index");
return mav;
}
}


index.jsp
<c:forEach var="student" items="${studentList }">
<tr>
<td>${student.id }</td>
<td>${student.title }</td>
<td>${student.content }</td>
</tr>
</c:forEach>

但这只能简单显示,如果我要分页显示,怎么修改?请教高手指点。由于本人初学,麻烦写出详细代码,谢谢!!
...全文
108 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Inhibitory 2014-12-28
  • 打赏
  • 举报
回复
分页于SpringMVC没有任何关系: 1. SQL实现的分页查询,每个数据库的分页语句都不一样,HTML里显示所有查询到的结果 2. SQL查询出所有结果,HTML里显示出想要的那一页的数据
u010442195 2014-12-27
  • 打赏
  • 举报
回复
前几天回复过一个帖子也是说分页的,里面有我的代码。。。地址http://bbs.csdn.net/topics/390959503

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧