猿问

使用springMVC框架时,怎样在controller里获得Session?

使用springMVC框架时,怎样在controller里获得Session


交互式爱情
浏览 1667回答 1
1回答

汪汪一只猫

public static HttpSession getSession() {HttpSession session = null;try {session = getRequest().getSession();} catch (Exception e) {}return session;}public static HttpServletRequest getRequest() {ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();return attrs.getRequest();}通过上述两个方法获取,减少了方法中的参数个数
随时随地看视频慕课网APP
我要回答