controller
@RequestMapping(value = "loginIn", method = RequestMethod.POST)
public ResultModel loginIn(@RequestBody UserDTO user, HttpServletRequest request, HttpServletResponse response)
{
TransResult transResult = userService.loginIn(user);
if(transResult.isSuccess())
{
HttpSession session = getRequest().getSession();
session.setAttribute("name",user.getUsername());
session.setAttribute("id",user.getPassword());
return this.resultResponseSuccess(new ContentModel(transResult.getObject()));
}else{
return this.resultResponseFault(new ContentModel(transResult.getObject()));
}
}
@RequestMapping(value = "register", method = RequestMethod.POST)
public ResultModel register(@RequestBody UserDTO user,HttpServletRequest request, HttpServletResponse response)
{
TransResult transResult = userService.register(user);
if(transResult.isSuccess())
{
return this.resultResponseSuccess(new ContentModel(transResult.getObject()));
}else{
return this.resultResponseFault(new ContentModel(transResult.getResultInfoDesc()));
}
}
拦截器
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
Object id = request.getSession().getAttribute("id");//这里的值为空
if(id!=null)
{
return true;
}
System.out.println("已拦截");
return false;
}
配置
@Override
public void addInterceptors(InterceptorRegistry registry) {
//跨域拦截
registry.addInterceptor(allowCrossDomainInterceptor)
.addPathPatterns("/**/register");
super.addInterceptors(registry);
}
现在就是登录完之后获取不到session