springMVC+thymeleaf form表单提交前后台数据传递

时间:2019-04-30 12:19:11   收藏:0   阅读:2132
@RequestMapping(value = "/add", method=RequestMethod.POST) 
public
String save(@ModelAttribute(value="message") Message message) { ... }
<form action="#" th:action="@{/add}" th:object="${message}" method="post">
<input type="text" th:field="*{info}" /> 
<input type="submit" />
</form> 
1 public class Message { 
2     private String info; 
3 public String getInfo() { 
4     return info; 
5 } 
6 public void setInfo(String info) { 
7     this.info= info; 
8 } 
9 } 

特别注意 th:field

这个属性在Spring-mvc里很重要,承担着绑定后台Bean属性的重任
th:field必须是选择表达式(*{…})

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!