您的位置:首页 > 编程语言 > Java开发

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

2017-03-21 18:38 459 查看

springMVC+thymeleaf 简单例子

后端

@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实体类

public class Message {
private String info;

public String getInfo() {
return info;
}

public void setInfo(String info) {
this.info= info;
}
}


特别注意  th:field

这个属性在Spring-mvc里很重要,承担着绑定后台Bean属性的重任

th:field必须是选择表达式(*{…})。

<div th:object="${book}">
...
<span th:text="*{title}">...</span>
...
</div>


前面选择了book,接下来就按照它求值。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐