【发布时间】:2015-08-23 07:11:01
【问题描述】:
我想编写自定义注解,根据注解修改 Spring 请求或路径参数。例如,而不是这个代码:
@RequestMapping(method = RequestMethod.GET)
public String test(@RequestParam("title") String text) {
text = text.toUpperCase();
System.out.println(text);
return "form";
}
我可以注释@UpperCase:
@RequestMapping(method = RequestMethod.GET)
public String test(@RequestParam("title") @UpperCase String text) {
System.out.println(text);
return "form";
}
有可能吗?如果可以,我该怎么做?
【问题讨论】:
-
看
HandlerMethodArgumentResolver界面。 -
你也可以用spring AOP做到这一点;你会使用像
@Before("@annotation(my.pkg.annotation.UpperCase)")这样注释的方法,然后在方法中转换参数。
标签: java spring spring-mvc spring-annotations request-mapping