看到@RestController=@Controller+@ResponseBody的效果,于是我写了一个自定义注解来组合,如下:@Target({ElementType.METHOD,ElementType.TYPE})@Retention(RetentionPolicy.RUNTIM...
看到@RestController=@Controller+@ResponseBody的效果,于是我写了一个自定义注解来组合,如下:
@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RequestMapping
@ResponseBody
public @interface AjaxRequestMapping {
String name() default "";
String[] value() default {};
RequestMethod[] method() default { RequestMethod.POST };
String[] params() default {};
String[] headers() default {};
String[] consumes() default {};
String[] produces() default { "application/json;charset=utf-8" };
}
希望效果是用:
@AjaxRequestMapping("upload/file")
来替代原本的
@ResponseBody
@RequestMapping(value = "upload/file", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
但是结果导致所有的请求都响应400异常,显然@AjaxRequestMapping的属性没有被@RequestMapping所获取。
请问大家,怎样才能起到@AjaxRequestMapping=@ResponseBody+@RequestMapping的效果?
展开