import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import org.springframework.session.ExpiringSession;
import org.springframework.session.SessionRepository;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
// 通过sessionId设置session
@Resource(name="sessionRepository")
private SessionRepository<ExpiringSession> sessionRepository;
@RequestMapping(value = "sets", method = {RequestMethod.GET,RequestMethod.POST})
public String sets(HttpSession session) throws IOException {
session.setAttribute("test", "test111");
return session.getId()+"|||"+session.getAttribute("test");
}
@RequestMapping(value = "gets", method = {RequestMethod.GET,RequestMethod.POST})
public String gets(String id) throws IOException {
return sessionRepository.getSession(id).getAttribute("test");
}