Spring RequestMapping参数自定义注释
在我的web应用程序中,我有许多地方需要检索当前记录的帐户(从会话) 这段代码重复了很多次。我想知道这是否可能使我的请求看起来像这样:Spring RequestMapping参数自定义注释,spring,annotations,Spring,Annotations,在我的web应用程序中,我有许多地方需要检索当前记录的帐户(从会话) 这段代码重复了很多次。我想知道这是否可能使我的请求看起来像这样: @RequestMapping(value="/something", method=RequestMethod.POST) public String handleSomething( @RequestParam String someParam, @Account Account account) { ... } 其中@Ac
@RequestMapping(value="/something", method=RequestMethod.POST)
public String handleSomething(
@RequestParam String someParam,
@Account Account account) { ... }
其中@Account是我的自定义注释
如何让spring处理此注释?使用(或对于低于3.1的版本)
要启用参数解析器,请执行以下操作:
- 如果使用
,请使您的@EnableWebMvc
@配置实现
并覆盖webmvcconfiguer
addArgumentResolvers()
- 如果您使用
-请使用
属性参数解析器
- 对于旧版本,您可能需要手动声明
,并设置其AnnotationMethodHandlerAdapter
CustomArgumentResolver
@RequestMapping(value="/something", method=RequestMethod.POST)
public String handleSomething(
@RequestParam String someParam,
@Account Account account) { ... }