當前位置: 首頁>>代碼示例>>Java>>正文


Java HandlerMethod類代碼示例

本文整理匯總了Java中org.springframework.web.method.HandlerMethod的典型用法代碼示例。如果您正苦於以下問題:Java HandlerMethod類的具體用法?Java HandlerMethod怎麽用?Java HandlerMethod使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HandlerMethod類屬於org.springframework.web.method包,在下文中一共展示了HandlerMethod類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: preHandle

import org.springframework.web.method.HandlerMethod; //導入依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    if (handler instanceof HandlerMethod) {
        HandlerMethod handlerMethod = ((HandlerMethod) handler);
        Method method = handlerMethod.getMethod();
        final Permission annotation = method.getAnnotation(Permission.class);
        if (Objects.isNull(annotation)) {
            return Boolean.TRUE;
        }
        final boolean login = annotation.isLogin();
        if (login) {
            if (!LoginServiceImpl.LOGIN_SUCCESS) {
                request.setAttribute("code","404");
                request.setAttribute("msg", "請您先登錄!");
                request.getRequestDispatcher("/").forward(request, response);
                return Boolean.FALSE;
            }
        }
    }
    return super.preHandle(request, response, handler);
}
 
開發者ID:yu199195,項目名稱:happylifeplat-transaction,代碼行數:22,代碼來源:AuthInterceptor.java

示例2: preHandle

import org.springframework.web.method.HandlerMethod; //導入依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    if (!supports(handler)) {
        return true;
    }

    HandlerMethod handlerMethod = (HandlerMethod) handler;
    Class<?> handlerClass = handlerMethod.getMethod().getDeclaringClass();
    LoginIgnored annotation = handlerMethod.getMethodAnnotation(LoginIgnored.class);
    if (annotation == null) {
        annotation = AnnotationUtils.findAnnotation(handlerClass, LoginIgnored.class);
    }
    if (annotation != null) {
        return true;
    }

    return doLogin(request, response);
}
 
開發者ID:zouzhirong,項目名稱:configx,代碼行數:19,代碼來源:LoginInterceptor.java

示例3: roleControl

import org.springframework.web.method.HandlerMethod; //導入依賴的package包/類
private boolean roleControl(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod, TokenUser user){
    Object target=handlerMethod.getBean();
    Class<?> clazz=handlerMethod.getBeanType();
    Method m=handlerMethod.getMethod();
    if (clazz!=null && m!=null){
        boolean isClzAnnotation= clazz.isAnnotationPresent(Permission.class);
        boolean isMethondAnnotation=m.isAnnotationPresent(Permission.class);
        Permission rc=null;
        if(isMethondAnnotation){
            rc=m.getAnnotation(Permission.class);
        }else if(isClzAnnotation){
            rc=clazz.getAnnotation(Permission.class);
        }
        int privilege = user.getPrivilege();
        assert rc != null;
        for (Privilege i:rc.value()){//如果在權限表中找到
            if (i.getCode() == privilege){
                return true;
            }
        }
    }
    return false;
}
 
開發者ID:MasonQAQ,項目名稱:WeatherSystem,代碼行數:24,代碼來源:PermissionsInterceptor.java

示例4: getAccessUser

import org.springframework.web.method.HandlerMethod; //導入依賴的package包/類
protected AdminUser getAccessUser(HttpServletRequest request, LoggingContext loggingContext) {
	if(loggingContext.getHttpAccessLogging().isLogin()){ //用戶正在登錄
		HandlerMethod handlerMethod = loggingContext.getHandlerMethod();
		MethodParameter[] methodParameters = handlerMethod.getMethodParameters();
		if(methodParameters != null){
			for(MethodParameter methodParameter : methodParameters){
				if(methodParameter.hasParameterAnnotation(RequestBody.class) && AdminUser.class.equals(methodParameter.getParameterType())){
					HttpRequestParameter requestParameter = loggingContext.getHttpAccessLog().getRequestParameter();
					Object requestBody = requestParameter.getBody();
					MediaType contentType = loggingContext.getHttpAccessLog().getRequestContentType();
					if (contentType != null && requestBody != null && requestBody instanceof Map && MediaType.APPLICATION_JSON.getType().equals(contentType.getType())) {
						Map<String,Object> requestBodyMap = (Map<String, Object>) requestBody;
						return adminUserService.getUserByUserName(MapUtils.getString(requestBodyMap, "userName"), false);
					}
				}
			}
		}
		return null;
	}else{ //用戶已登錄
		LoginToken<AdminUser> loginToken = (LoginToken<AdminUser>) ShiroUtils.getSessionAttribute(LoginToken.LOGIN_TOKEN_SESSION_KEY);
		return loginToken == null ? null : loginToken.getLoginUser();
	}
}
 
開發者ID:penggle,項目名稱:xproject,代碼行數:24,代碼來源:DefaultHttpAccessLoggingInterceptor.java

示例5: doResolveException

import org.springframework.web.method.HandlerMethod; //導入依賴的package包/類
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
	ModelAndView mav = null;
	try {
		if(!(ex instanceof SystemException)){
			logger.error(ex.getMessage(), ex); //未知異常記錄下來
		}
		if(handler instanceof HandlerMethod){
			if(isAsyncRequest(request, response, handler)){ //異步請求的異常處理
				return handle4AsyncRequest(request, response, handler, ex);
			} else { //正常頁麵跳轉的同步請求的異常處理
				return handle4SyncRequest(request, response, handler, ex);
			}
		}
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
	}
	return mav;
}
 
開發者ID:penggle,項目名稱:xproject,代碼行數:19,代碼來源:AbstractGlobalHandlerExceptionResolver.java

示例6: isRequestSupport

import org.springframework.web.method.HandlerMethod; //導入依賴的package包/類
/**
 * 請求是否支持訪問日誌記錄
 * @param request
 * @return
 */
protected boolean isRequestSupport(HttpServletRequest request) {
	try {
		if(!this.isAsyncDispatch(request) && !this.isAsyncStarted(request)){
			HandlerExecutionChain handlerExecutionChain = this.getSpringMvcHandlerMethodMapping().getHandler(request);
			if(handlerExecutionChain != null && handlerExecutionChain.getHandler() != null && handlerExecutionChain.getHandler() instanceof HandlerMethod){
				HandlerMethod handlerMethod = (HandlerMethod) handlerExecutionChain.getHandler();
				HttpAccessLogging httpAccessLogging = handlerMethod.getMethodAnnotation(HttpAccessLogging.class);
				return httpAccessLogging != null;
			}
		}
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
	}
	return false;
}
 
開發者ID:penggle,項目名稱:xproject,代碼行數:21,代碼來源:HttpAccessLoggingServletStreamFilter.java

示例7: isAsyncRequest

import org.springframework.web.method.HandlerMethod; //導入依賴的package包/類
/**
 * 判斷請求是否是異步請求
 * @param request
 * @param handler
 * @return
 */
public static boolean isAsyncRequest(HttpServletRequest request, Object handler){
	boolean isAsync = false;
	if(handler instanceof HandlerMethod){
		HandlerMethod handlerMethod = (HandlerMethod) handler;
		isAsync = handlerMethod.hasMethodAnnotation(ResponseBody.class);
		if(!isAsync){
			Class<?> controllerClass = handlerMethod.getBeanType();
			isAsync = controllerClass.isAnnotationPresent(ResponseBody.class) || controllerClass.isAnnotationPresent(RestController.class);
		}
		if(!isAsync){
			isAsync = ResponseEntity.class.equals(handlerMethod.getMethod().getReturnType());
		}
	}
	if(!isAsync){
		isAsync = HttpUtils.isAsynRequest(request);
	}
	return isAsync;
}
 
開發者ID:penggle,項目名稱:xproject,代碼行數:25,代碼來源:SpringMvcUtils.java

示例8: preHandle

import org.springframework.web.method.HandlerMethod; //導入依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
	
	if (!(handler instanceof HandlerMethod)) {
		return super.preHandle(request, response, handler);
	}
	
	if (!isLogin(request)) {
		HandlerMethod method = (HandlerMethod)handler;
		Permession permission = method.getMethodAnnotation(Permession.class);
		if (null == permission || permission.permession()) {
			throw new Exception("登陸失效");
		}
	}
	
	return super.preHandle(request, response, handler);
}
 
開發者ID:shiziqiu,項目名稱:shiziqiu-configuration,代碼行數:18,代碼來源:PermissionInterceptor.java

示例9: preHandle

import org.springframework.web.method.HandlerMethod; //導入依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    if (handler instanceof HandlerMethod) {
        HandlerMethod handlerMethod = ((HandlerMethod) handler);
        Method method = handlerMethod.getMethod();
        final Permission annotation = method.getAnnotation(Permission.class);
        if (Objects.isNull(annotation)) {
            return Boolean.TRUE;
        }
        final boolean login = annotation.isLogin();
        if (login) {
            if (!LoginServiceImpl.LOGIN_SUCCESS) {
                request.setAttribute("code","404");
                request.setAttribute("msg", "請登錄!");
                request.getRequestDispatcher("/").forward(request, response);
                return Boolean.FALSE;
            }
        }
    }
    return super.preHandle(request, response, handler);
}
 
開發者ID:yu199195,項目名稱:myth,代碼行數:22,代碼來源:AuthInterceptor.java

示例10: initModel

import org.springframework.web.method.HandlerMethod; //導入依賴的package包/類
/**
 * Populate the model in the following order:
 * <ol>
 * 	<li>Retrieve "known" session attributes -- i.e. attributes listed via
 * 	{@link SessionAttributes @SessionAttributes} and previously stored in
 * 	the in the model at least once
 * 	<li>Invoke {@link ModelAttribute @ModelAttribute} methods
 * 	<li>Find method arguments eligible as session attributes and retrieve
 * 	them if they're not	already	present in the model
 * </ol>
 * @param request the current request
 * @param mavContainer contains the model to be initialized
 * @param handlerMethod the method for which the model is initialized
 * @throws Exception may arise from {@code @ModelAttribute} methods
 */
public void initModel(NativeWebRequest request, ModelAndViewContainer mavContainer, HandlerMethod handlerMethod)
		throws Exception {

	Map<String, ?> attributesInSession = this.sessionAttributesHandler.retrieveAttributes(request);
	mavContainer.mergeAttributes(attributesInSession);

	invokeModelAttributeMethods(request, mavContainer);

	for (String name : findSessionAttributeArguments(handlerMethod)) {
		if (!mavContainer.containsAttribute(name)) {
			Object value = this.sessionAttributesHandler.retrieveAttribute(request, name);
			if (value == null) {
				throw new HttpSessionRequiredException("Expected session attribute '" + name + "'");
			}
			mavContainer.addAttribute(name, value);
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:34,代碼來源:ModelFactory.java

示例11: preHandle

import org.springframework.web.method.HandlerMethod; //導入依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
	
	if (!(handler instanceof HandlerMethod)) {
		return super.preHandle(request, response, handler);
	}
	
	if (!ifLogin(request)) {
		HandlerMethod method = (HandlerMethod)handler;
		PermessionLimit permission = method.getMethodAnnotation(PermessionLimit.class);
		if (permission == null || permission.limit()) {
			response.sendRedirect(request.getContextPath() + "/toLogin");
			//request.getRequestDispatcher("/toLogin").forward(request, response);
			return false;
		}
	}
	
	return super.preHandle(request, response, handler);
}
 
開發者ID:mmwhd,項目名稱:stage-job,代碼行數:20,代碼來源:PermissionInterceptor.java

示例12: resolveException

import org.springframework.web.method.HandlerMethod; //導入依賴的package包/類
@Override
public ModelAndView resolveException(HttpServletRequest request,
		HttpServletResponse response, Object handler, Exception ex) {
	logger.error("WebExceptionResolver:{}", ex);
	
	ModelAndView mv = new ModelAndView();
	HandlerMethod method = (HandlerMethod)handler;
	ResponseBody responseBody = method.getMethodAnnotation(ResponseBody.class);
	if (responseBody != null) {
		response.setContentType("application/json;charset=UTF-8");
		mv.addObject("result", JacksonUtil.writeValueAsString(new ReturnT<String>(500, ex.toString().replaceAll("\n", "<br/>"))));
		mv.setViewName("/common/common.result");
	} else {
		mv.addObject("exceptionMsg", ex.toString().replaceAll("\n", "<br/>"));	
		mv.setViewName("/common/common.exception");
	}
	return mv;
}
 
開發者ID:mmwhd,項目名稱:stage-job,代碼行數:19,代碼來源:WebExceptionResolver.java

示例13: resolveException

import org.springframework.web.method.HandlerMethod; //導入依賴的package包/類
@Override
	public ModelAndView resolveException(HttpServletRequest request,
		 HttpServletResponse response, Object handler, Exception e) {
		// log記錄異常
		LOGGER.error(e.getMessage(), e);
		// 非控製器請求照成的異常
		if (!(handler instanceof HandlerMethod)) {
			return new ModelAndView("error/500");
		}
		HandlerMethod handlerMethod = (HandlerMethod) handler;

		if (WebUtils.isAjax(handlerMethod)) {
			Result result = new Result();
			result.setMsg(e.getMessage());
			MappingJackson2JsonView view = new MappingJackson2JsonView();
			view.setObjectMapper(jacksonObjectMapper);
			view.setContentType("text/html;charset=UTF-8");
			return new ModelAndView(view, BeanUtils.toMap(result));
		}

		// 頁麵指定狀態為500,便於上層的resion或者nginx的500頁麵跳轉,由於error/500不適合對用戶展示
//		response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
		return new ModelAndView("error/500").addObject("error", e.getMessage());
	}
 
開發者ID:TomChen001,項目名稱:xmanager,代碼行數:25,代碼來源:ExceptionResolver.java

示例14: onApplicationEvent

import org.springframework.web.method.HandlerMethod; //導入依賴的package包/類
@Override
public void onApplicationEvent ( ContextRefreshedEvent event ) {
	final RequestMappingHandlerMapping requestMappingHandlerMapping =
		applicationContext.getBean( RequestMappingHandlerMapping.class );
	final Map< RequestMappingInfo, HandlerMethod > handlerMethods =
		requestMappingHandlerMapping.getHandlerMethods();

	this.handlerMethods = handlerMethods;

	handlerMethods.keySet().forEach( mappingInfo -> {
		Map< Set< String >, Set< RequestMethod > > mapping = Collections.singletonMap(
			mappingInfo.getPatternsCondition().getPatterns() ,
			this.getMethods( mappingInfo.getMethodsCondition().getMethods() )
		);
		requestMappingInfos.add( mapping );
	} );

	requestMappingUris.addAll(
		handlerMethods.keySet()
					  .parallelStream()
					  .map( mappingInfo -> mappingInfo.getPatternsCondition().getPatterns() )
					  .collect( Collectors.toList() )
	);

}
 
開發者ID:yujunhao8831,項目名稱:spring-boot-start-current,代碼行數:26,代碼來源:BasicBeanConfig.java

示例15: doResolveException

import org.springframework.web.method.HandlerMethod; //導入依賴的package包/類
@Override
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
                                          Object _handler, Exception ex) {
    HandlerMethod handler = (HandlerMethod) _handler;
    if (handler == null) {
        return null;
    }
    Method method = handler.getMethod();
    if (method.isAnnotationPresent(JsonBody.class) && ex != null) {
        logger.error("server is error", ex);
        Object value = null;
        if (ex instanceof ServiceException) {
            value = new JsonResult<Object>(((ServiceException) ex).getCode(), ex.getMessage());
        } else {
            value = new JsonResult<Object>(-1, ex.getMessage());
        }
        try {
            JsonUtil.writeValue(response.getWriter(), value);
        } catch (IOException e) {
            Throwables.propagateIfPossible(e);
        }
        return ModelAndViewResolver.UNRESOLVED;
    }
    return null;
}
 
開發者ID:didapinchegit,項目名稱:rocket-console,代碼行數:26,代碼來源:JsonBodyExceptionResolver.java


注:本文中的org.springframework.web.method.HandlerMethod類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。