spring mvc中RequestContextHolder分析

RequestContextHolder

当我们需要在service层获取request和response时,我们可以在RequestContextHolder中获取。
使用方法:

        RequestAttributes requsetAttributes = RequestContextHolder.currentRequestAttributes();
		//RequestAttributes requsetAttributes = RequestContextHolder.getRequestAttributes();
		String str = (String) requsetAttributes.getAttribute("name", RequestAttributes.SCOPE_SESSION);
		HttpServletRequest request = ((ServletRequestAttributes) requsetAttributes).getRequest();
		HttpServletResponse reponse = ((ServletRequestAttributes) requsetAttributes).getResponse();





    原文作者:Spring MVC
    原文地址: https://blog.csdn.net/qq_20143059/article/details/82783276
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞