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


  • 后端:
@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> 
  • Message实体类
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必须是选择表达式(*{…})

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM