「Spring Boot」セッションIDを取得するサンプル
書式
request.getSession().getId()
使用例
public class UserController {
// HttpSessionの場合
@GetMapping
String login(HttpSession session) {
String sesId = session.getId();
return "top";
}
// HttpServletRequestの場合
@GetMapping
String index(HttpServletRequest req) {
String sessId;
sessId = req.getSession().getId();
return "top";
}
}