81,094
社区成员
发帖
与我相关
我的任务
分享
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;
}
}
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;
}
}
@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;
}
}
<c:forEach var="student" items="${studentList }">
<tr>
<td>${student.id }</td>
<td>${student.title }</td>
<td>${student.content }</td>
</tr>
</c:forEach>