我从DAO获取的值存储在变量editVal
中,页面返回edit.jsp现在如何在edit.jsp页面中获取可变editVal
值。
控制器页面:
@RequestMapping(value="edit", method=RequestMethod.GET)//String
public ModelAndView callgetSuccess(@ModelAttribute("id")String Id, BindingResult result, ModelMap model) {
ModelAndView shop=new ModelAndView();
shopModel shModel=new shopModel();
if(result.hasErrors()){
System.out.println("error");
return new ModelAndView("edit","shopModel",editVal);//"edit"
}else{
shModel = shopService1.editshop(Id);
model.addAttribute("shopModel",shModel);
shop.addObject("shopModel", shModel);
return new ModelAndView("edit","shopModel",shModel);
}
edit.jsp文件
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<html>
<body>
<h2>Hello World!</h2>
<form>
<h1>Success</h1>
edit page
<c:out value="${id}" />
</form>
</body>
</html>
Edit.jsp Page Imge edit jsp page image
答案 0 :(得分:0)
由于editVal
是一个字符串,您可以访问它<c:out value="${shopModel}" />
如果是一个字符串列表,则可以使用以下内容
<c:forEach var="shop" items="${shopModel}">
<c:out value="${shop}" />
</c:forEach>
如果是对象列表,则var.<object attribute name>
如下
<c:forEach items="${shopModel}" var="shop">
<tr>
<td>${shop.name}</td>
<td>${shop.number}</td>
...
</tr>
</c:forEach>