标签:get 对象 service tco xml文件 func let 文件中 ext
1.在web.xml文件中添加监听器,然后通过注解注入request:
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
@Autowired
private HttpServletRequest request;
2.直接在service层普通类中获取
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
在service层注入HttpSession对象,然后直接获取
@Autowired
private HttpSession session;
public void getsession (){
String name = (String) session.getAttribute("name");
}
Spring在service层获取session和request
标签:get 对象 service tco xml文件 func let 文件中 ext
原文地址:https://www.cnblogs.com/naliyixin/p/9172098.html