pom.xml添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
html中声明
提交表单
获取提交表单业面
//获取提交表单页面
@RequestMapping("/post")
public String post_test(Model model) {
model.addAttribute("person", new Person());
return "post_test";
}
//提交表单动作
@PostMapping("/post")
@ResponseBody
public String post_test(Person person) {
return person.getName() + ":" + person.getAge();
}
html代码
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>PostTest</title>
</head>
<body>
<form action="#" th:action="@{/post}" th:object="${person}" method="post">
<p>Id: <input type="text" th:field="*{name}" /></p>
<p>Message: <input type="text" th:field="*{age}" /></p>
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</form>
</body>
</html>
测试