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