Thymeleaf文本及预算:
示例如下:
表单提交:
增加subscribe.html页面:
内容如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form action="#" th:action="@{/Hello/subscribe}" th:object="${user}" method="post"> <fieldset> <input type="text" name="name" /> <input type="submit" value="名称提交"/> </fieldset> </form> <form th:attr="action=‘#‘,action=@{/Hello/subscribe},object=${user},method=‘post‘"> <fieldset> <input type="text" name="age" /> <input type="submit" value="年龄提交"/> </fieldset> </form> </body> </html>
如下所示:
后台Controller增加:
@RequestMapping(value = "GetPage3", method = RequestMethod.GET) public String getsubscribe( ) { return "subscribe"; } @RequestMapping(value = "subscribe", method = RequestMethod.POST) public String getPage1ByName(@ModelAttribute User user) { ModelMap map = new ModelMap(); user.getName(); user.getAge(); map.addAttribute("user",user); return "page1"; }
如下所示:
运行结果:
名称提交:
年龄提交:
原文:https://www.cnblogs.com/feichangnice/p/10168510.html