
package com.manage.config;

import com.manage.entity.Power_Menu;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebArgumentResolver;
import org.springframework.web.context.request.NativeWebRequest;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: ljx
 * @Date: 2019/4/22 19:10
 * @Version 1.0
 * 获取当前保存在session里的对象 可通过在方法参数直接获取Power_User
 */
public class CurrentUserResolver implements WebArgumentResolver {

    @Override
    public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest nativeWebRequest) throws Exception {
        if(methodParameter.getParameterType() != null && methodParameter.getParameterType().equals(Power_Menu.class)){
            HttpServletRequest request = nativeWebRequest.getNativeRequest(HttpServletRequest.class);
            Object currentUser = request.getSession().getAttribute("CURRENT_USER");
            return currentUser;
        }
        return UNRESOLVED;
    }
}
