被@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);