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";
        
    }

  

posted @ 2022-10-18 00:25  青竹之下  阅读(226)  评论(0编辑  收藏  举报