被@ModelAttribute注解的方法会在controller每个方法执行之前都执行,返回值会保存在model中 绝地灬酷狼 2022-04-16 07:07 68阅读 0赞 被@ModelAttribute注解的方法会在controller每个方法执行之前都执行,返回值会保存在model中。 1、如果方法中有返回值,则key为方法名public/private后指定的返回值类型,如: public int a() private String b() public Student c() 这时候的key就是int/String/student,赋值格式如下: model.addAttribute("string", abc); model.addAttribute("int", number); model.addAttribute("student", stu); 2、如果没有返回值,如 public void a() private void b() 则key可以随意赋值 model.addAttribute(key,value);
还没有评论,来说两句吧...