我希望能够拥有以下内容:
@Controller
public class MyController {
@RequestMapping(value="/someurl", method=RequestMethod.GET)
@PreProcess
@PostProcess
public String doStuff(ModelMap map) {
//do stuff
return "someurl";
}
}
The @PreProcess
and @PostProcess
被任意命名为注释。
我一直在寻找这方面的工作示例,但找不到。我看过 AOP 和使用@Aspect
注释,但我发现它相当复杂。我正在尝试做的事情的一个可行的例子会很棒。
我过去曾尝试过 Spring Security,但这并不是我所需要的,因为我需要自定义处理,几乎是我想要的任何东西。
我知道.Net MVC 中提供了此功能。希望春季也能上市。
任何帮助或指示真的很感激。
您可以使用注释方法@ModelAttribute http://static.springsource.org/spring/docs/3.0.x/api/org/springframework/web/bind/annotation/ModelAttribute.html在控制器方法之前执行方法。或者使用interceptor http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-handlermapping-interceptor
示例为@ModelAttribute
@Controller
public class MyController {
@RequestMapping(value="/someurl", method=RequestMethod.GET)
public String doStuff(@ModelAttribute("something") Something something, ModelMap map) {
//do stuff
// here you can do what you want with something it has been provided to you in the method parameters
return "someurl";
}
@ModelAttribute("something")
public Something something() {
// do what you need
return new Something();
}
}
The something()
方法将在每个具有@RequestMapping
注释,因此在之前doStuff()
method.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)