模仿@RequestParam
自定义一个注解@CustomParam
,实现与@RequestParam
同样的功能,只不过@RequestParam
注解是从请求路径上获取参数,而我们自定义的@CustomParam
注解则是从 request body 中获取参数
第一步,定义注解
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface CustomParam {
/**
* Alias for {@link #name}.
*/
@AliasFor("name")
String value() default "";
/**
* The name of the request parameter to bind to.
*
* @since 4.2
*/
@AliasFor("value")
String name() default "";
/**
* Whether the parameter is required.
* <p>Default is {@code true}, leading to an exception thrown in case
* of the parameter missing in the request. Swit