<tr th:each="item:${session.p1}">
<!-- 查找数据 获取当前点击的对应的id-->
<!--item.getKey() 获取当前map的键-->
<!-- item.value.id 获取map集合变量id的值-->
<td name="price" th:text="${item.getKey()}"></td>
<td name="price" th:text="${item.value.id}"></td>
<td name="price" th:text="${item.value.st1}"></td>
<td name="price" th:text="${item.value.st2}"></td>
</tr>
@WebServlet("/index")
public class Ceshi extends ViewBaseServlet {
static Map<String,Pring> p1=new HashMap();
static {
p1.put("1",new Pring(1, "香蕉","20"));
p1.put("2",new Pring(2, "苹果","12"));
p1.put("3",new Pring(3, "西瓜","30"));
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
HttpSession session = req.getSession();
session.setAttribute("p1", p1);
super.processTemplate("index",req,resp);
}
}
通过
th:each="item:${session.p1}"遍历map集合
item.value.id 获取map集合变量id的值
item.getKey() 获取当前map的键
使用这个对数据进行保存
HttpSession session = req.getSession(); session.setAttribute("p1", p1);
也可以不用静态