我是新來的spring和hibernate.I使用POJO類來維護sessoin data.i把範圍作爲一個會話。這裏春季會話範圍使用用戶登錄
@Component
@Scope("session")
public class SessionInfo {
private int userId;
private String loggingUser;
// getter and setter methods
}
然後我的控制器類設定爲範圍=「請求」和方法在控制器I能通過sessionInfo類和設置/獲取會話數據。
@RequestMapping(method = RequestMethod.GET)
public String index(Model model,SessionInfo session) {
session.setLoggingUser("[email protected]");
// set model attributes ....
return "BusinessCategory/index";
}
這就是我如何維護會話數據在我的應用程序。通過這種方式,每當我需要在需要的每個方法中傳遞sessionInfo類並檢查會話對象中是否存在任何用戶時,Is就是正確與否。也不能使用intercepter。如果不是什麼是在春季維護會話數據的最佳方式。
你是否在使用Spring Security管理登錄到你的應用程序?如果是這樣,他們已經有一個抽象的會話中到達用戶。 –
Thax Ryan,我使用spring安全登錄。如何存儲登錄用戶的會話詳細信息 – Amila