spring获取session设置session
2021-04-02 13:28
标签:htm text charset log 用户 tps return class attr spring获取session设置session 标签:htm text charset log 用户 tps return class attr 原文地址:https://www.cnblogs.com/king0207/p/13490190.html获取session,设置session
@RequestMapping(value = "/loginUser", produces = {"text/html;charset=utf-8"}, method = RequestMethod.POST)
public String login(@RequestParam(value = "user", required = false) String user,
@RequestParam(value = "password") String password,
@RequestParam(value = "telephone") String telephone,
HttpSession session) {
。。。。。。省略一大段代码
//这里设置一下session,保存登录的用户信息到session中去
session.setAttribute("user",userDO);
}
获取session。
/**
* 登录的时候进到主页面
* @return
*/
@RequestMapping("/")
public ModelAndView requestMapping(HttpSession session) {
ModelAndView map = new ModelAndView("index");
System.out.println(session.getAttribute("user"));
userMapper userMapper = (userMapper)session.getAttribute("user");
if(userMapper!=null)
map.addObject("userid", userMapper.getUserid());
return map;
}
文章标题:spring获取session设置session
文章链接:http://soscw.com/index.php/essay/71397.html