0
我試圖在會話屬性中存儲一些數據,但在嘗試更新後遇到一些奇怪的問題。我正在使用Spring引導1.2.4更新@SessionAttributes值的彈簧
我創建了一個測試控制器來描述該問題。
@RestController
@SessionAttributes(TestController.ATTRIBUTE)
public class TestController {
public static final String ATTRIBUTE = "attribute";
@ResponseStatus(value = HttpStatus.OK)
@RequestMapping(value = "/set/{value}", method = RequestMethod.POST)
public void set(@PathVariable Long value, HttpSession session) {
System.out.println("Set value to: " + value + " session id:\t" + session.getId());
session.setAttribute(ATTRIBUTE, value);
}
@ResponseStatus(value = HttpStatus.OK)
@RequestMapping(value = "/get", method = RequestMethod.GET)
public void get(HttpSession session) {
System.out.println("Value: " + session.getAttribute(ATTRIBUTE) + " session id:\t\t" + session.getId());
}
}
例如,如果我調用這些方法是這樣的:
localhost:8080/set/1
localhost:8080/set/2
localhost:8080/get
我希望得到它看起來像這樣(會話ID除外)輸出:
Set value to: 1
Set value to: 2
Value: 2
不過我(會議ID包括):
Set value to: 1 session id: 9D6F9948E81654E4087F418EF6BF5157
Set value to: 2 session id: 9D6F9948E81654E4087F418EF6BF5157
Value: 1 session id: 9D6F9948E81654E4087F418EF6BF5157
在get&set方法中打印sesssion id,以確保您重新查看正確的會話 – 6ton
我已使用會話id更新了該問題。這是同一屆會議。 – Edd