标签:
1.读取数据库中的记录List<HashMap<String,String>> attributes;
2.Controller构造Model如下:
@RequestMapping("display.do")
public ModelAndView display(HttpServletRequest request, ModelMap model) {
List<HashMap<String, String>> myList = disService.getAllRecords();
model.addAttribute("list", myList);
/*此处可追加Attribute*/
return new ModelAndView("display.jsp");
}
3.display.jsp使用内嵌java显示记录
页面引入类
<%@ page import="java.util.List"%>
<%@ page import="java.util.HashMap"%>
获取list
<%
List<HashMap<String,String>> list = (List<HashMap<String,String>>)request.getAttribute("list");
%>
以table形式显示数据
<table style="width:100%">
<tr>
<td>value1</td>
<td>value2</td>
<td>value3</td>
</tr>
<%for (int i=0;i<list.size();i++){%>
<tr>
<td><%out.print(list.get(i).get("key1")); %></button></td>
<td><%out.print(list.get(i).get("key2")); %></td>
<td><%out.print(list.get(i).get("key3")); %></td>
</tr>
<%} %>
</table>
标签:
原文地址:http://www.cnblogs.com/liumuqiu/p/4435609.html