spring-boot表单提交

1.表单提交注意事项:

1.1entity类要有主键,自增id

@Entity
public class User {
    @Id
    @GeneratedValue
    private Integer id;
    private String email;
    private String name;
    private String pwd;
2.在访问到表单的controller类中增加对象模型

@Controller
@RequestMapping("/")
public class App {
    @RequestMapping
    public String index(Model model){
        model.addAttribute("user", new User());//表单中要提交的对象
        return "index";
    }
}
3.前端表单
 
 
4表单提交到greeting  th:action="@{/greeting}"
 
 
5.通过model.addAttribute属性,将user对象应用到indexresult页面中
 
 
 
 
 
 


猜你喜欢

转载自blog.csdn.net/yj310873325/article/details/79119131