Nov*_*ser 3 spring annotations spring-mvc
我用@ControllerAdvice标记了一个类
添加了一种方法
@ModelAttribute
public void setSourceAppId(Model model)
{
model.addAttribute("myattribute","1234");
}
Run Code Online (Sandbox Code Playgroud)
但是这种方法根本没有被调用.
我还没有使用一个setter方法使用modelattribute,所以我不能说这是一个错误的方法,但将其更改为getter将完成这项工作.此外,您不需要自己将其添加到模型中.Modelattribute正是这样处理的.
@ModelAttribute("myattribute")
public int getSourceAppId()
{
return 1234;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2223 次 |
| 最近记录: |