springboot的form表单数据封装为对象
参考:(68条消息) spring boot (五)表单处理_2020越努力越幸运的博客-CSDN博客_springboot表单
@GetMapping("/index") public String blog(Model model) { model.addAttribute("blogs",new Blog()); return "index"; }
index.html
<form action="#" th:action="@{/blogs/result}" th:object="${blogs}" method="post"> <input type="text" th:field="*{id}"> <input type="text" th:field="*{content}"> <input type="submit" value="提交"> </form>
@PostMapping("/blogs/result") public String create(@ModelAttribute Blog blog) { return "result"; }