退出登录仍然显示用户名
问题在与使用LocalThread与request的生命周期不吻合,解决方案如下:
@Autowired
private TicketService ticketService;
@Autowired
private UserService userService;
@RequestMapping(path = {"/index"}, method = {RequestMethod.GET})
public String bookList(Model model, @CookieValue("t")String t) {
//User host = hostHolder.getUser();
// 修改 2019.04.06 LocalThread生命周期与request差异巨大
//判断 t票是否存在, 来判断是否已经登录
User host = null;
Ticket ticket = ticketService.getTicket(t);
if (ticket != null){
host = userService.getUser(ticket.getUserId());
}
if (host != null) {
model.addAttribute("host", host);
}
loadAllBooksView(model);
return "book/books";
}