Spring - Redirect to another view with data binding
I think this question is quite easy if I know the keyword but I'm new to Spring so I need your help, any editing is appreciated.
This is how I can put and get an object data from a view.
@RequestMapping(method = RequestMethod.GET)
public String login(Map model) {
Member member = new Member(1, "admin", "admin", Boolean.TRUE, null);
model.put("member", member);
return "login";
}
// The parameters must be in order @Model, BindingResult, Map
@RequestMapping(method = RequestMethod.POST)
public String ProcessForm(@ModelAttribute("member") Member member, BindingResult result, Map model) {
dao = new JdbcMemberDao(MemberController.dataSource);
member = (Member) model.get("member");
Member tmp = dao.getUser(member.getUs开发者_开发知识库ername(), member.getPassword());
if (tmp != null) {
model.put("member", tmp);
return "phonelist";
}
return "login";
}
But what if I have a list of objects so how do I know to get the object I want :
@RequestMapping(value = "/phonelist", method = RequestMethod.GET)
public String getPhoneList(Map model) {
List<Phone> phones = dao.getPhones();
model.put("phones",phones);
return "phonelist";
}
the view of list of objects (using JSTL) :
<table id="phoneTable">
<tr><th id="name">Name</th><th id="brand">Brand</th><th id="price">Price</th></tr>
<c:forEach items="${phones}" var="phone">
<tr><td><c:out value="${phone.name}"/></td><td><c:out value="${phone.brand}"/></td><td><c:out value="${phone.price}"/></td></tr>
</c:forEach>
</table>
My question is:
- How can I create a view with link for every object so I can click to a specific item.
- get the specific item that I've just clicked.
Thanks a billion :)
This is addressed in Spring 3.1 with the new feature called "flash attributes":
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/mvc.html#mvc-flash-attributes
精彩评论