@ModelAttribute
所有的controller都继承一个基础的controller,
在基础controller中用@ModelAttribute修饰一个方法,就可以做到在执行所有的方法之前,先执行这个方法
例如:
public class BaseController {
@ModelAttribute
public void common(HttpServletRequest request, HttpServletResponse response)
{
//执行公共的东西
}
}例如:
@ModelAttribute
public void common(HttpServletRequest request, HttpServletResponse response) {
//执行公共的东西
System.out.println("执行公共方法");
try {
//转发
response.sendRedirect("/cxb/cxbIndex/index/home/intoIndex");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}引用文档:
http://docs.spring.io/spring/docs/4.2.9.RELEASE/spring-framework-reference/htmlsingle/
- 本文固定链接: http://www.ypbj.cc/post/192.html
- 转载请注明: yupang 于 余胖笔记 发表
《本文》有 0 条评论