0 评论0 浏览


public @interface  PersonValue {
     * Alias for {@link #name}.
    String value() default "";

     * The name of the request parameter to bind to.
     * @since 4.2
    String name() default "";

     * Whether the parameter is required.
     * <p>Defaults to {@code true}, leading to an exception being thrown
     * if the parameter is missing in the request. Switch this to
     * {@code false} if you prefer a {@code null} value if the parameter is
     * not present in the request.
     * <p>Alternatively, provide a {@link #defaultValue}, which implicitly
     * sets this flag to {@code false}.
    boolean required() default true;

     * The default value to use as a fallback when the request parameter is
     * not provided or has an empty value.
     * <p>Supplying a default value implicitly sets {@link #required} to
     * {@code false}.
    String defaultValue() default ValueConstants.DEFAULT_NONE;


2. 实现HandlerMethodArgumentResolver接口

public class PersonValueMethodArgumentResolver implements HandlerMethodArgumentResolver {

    public boolean supportsParameter(MethodParameter parameter) {
        return parameter.hasParameterAnnotation( PersonValue.class); }

    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
        try {
            HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);

            if (servletRequest != null) {
                String token = WebUtils.getCookie(servletRequest,"token").getValue();
                return JWTUtil.getPerson(token);
        } catch (Exception e) {
            return null;


        return null;



 <mvc:annotation-driven >
            <bean class="com.xxxx.xxx.xxxx.PersonValueMethodArgumentResolver"></bean>


  public @ResponseBody  Response doEditPass(@PersonValue  person,
      @RequestBody @Valid PwdEditCmd pwdEditCmd,
      HttpServletResponse response, HttpServletRequest request) {