Package com.github.zhangkaitao.shiro.chapter22.web.bind.method

Source Code of com.github.zhangkaitao.shiro.chapter22.web.bind.method.CurrentUserMethodArgumentResolver

package com.github.zhangkaitao.shiro.chapter22.web.bind.method;

import com.github.zhangkaitao.shiro.chapter22.web.bind.annotation.CurrentUser;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

/**
* <p>用于绑定@FormModel的方法参数解析器
* <p>User: Zhang Kaitao
* <p>Date: 13-1-12 下午5:01
* <p>Version: 1.0
*/
public class CurrentUserMethodArgumentResolver implements HandlerMethodArgumentResolver {

    public CurrentUserMethodArgumentResolver() {
    }

    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        if (parameter.hasParameterAnnotation(CurrentUser.class)) {
            return true;
        }
        return false;
    }

    @Override
    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
        CurrentUser currentUserAnnotation = parameter.getParameterAnnotation(CurrentUser.class);
        return webRequest.getAttribute(currentUserAnnotation.value(), NativeWebRequest.SCOPE_REQUEST);
    }
}
TOP

Related Classes of com.github.zhangkaitao.shiro.chapter22.web.bind.method.CurrentUserMethodArgumentResolver

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.