将属性范围会话添加到modelmap时会发生什么类型的事件?

时间:2015-11-22 12:03:19

标签: spring-mvc spring-security

我想要捕获事件添加属性"fullName"范围会话,我尝试使用ApplicationListener它不起作用。

这是我的cotroller

@SessionAttributes({ "fullName" })
public class LoginController {
@RequestMapping(value = "home", method = RequestMethod.POST)
ModelAndView loginPost(ModelMap model, @ModelAttribute User user, HttpSession session) {
    String fullName = loginService.getUserFullName(user);
    if (fullName == null) {
        model.addAttribute("error", "Username or password is invalid");
        return new ModelAndView("login");
    } else {
        model.addAttribute("fullName", fullName);
        return new ModelAndView("home", model);
    }
}

和听众

public class Listener implements ApplicationListener<ApplicationEvent> {
    private static int countUserOnline;

    public static int getCountUserOnline() {
        return countUserOnline;
    }
    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if (event instanceof HttpSessionDestroyedEvent) {
            countUserOnline--;
        }
        else if(event instanceof HttpSessionDestroyedEvent) {
            countUserOnline++;
        } 
    }
}

0 个答案:

没有答案