【发布时间】:2020-02-17 03:24:26
【问题描述】:
首先,当我调用API“/fetch/event/1221”时,我可以设置会话属性, 但是当我调用“fetch/partcipant”API 时,我将 httpSession 设为 null。 我该如何解决这个问题?
@RequestMapping(value = "/fetch/event/{eventId}", method = RequestMethod.GET)
public SuccessResponse<Event> fetchEvent(@PathVariable("eventId") String eventId, HttpServletRequest httpServletRequest) throws ExecutionException, InterruptedException {
Event event = eventService.getEventById(eventId);
HttpSession httpSession = httpServletRequest.getSession(false);
httpSession.setAttribute("event", event);
return new SuccessResponse<Event>(event);
}
@RequestMapping(value = "/fetch/participant", method = RequestMethod.GET)
public SuccessResponse<List<Participant>> getListOfActiveParticipants(HttpServletRequest httpServletRequest) throws ExecutionException, InterruptedException {
HttpSession httpSession = httpServletRequest.getSession(false);
Event event = (Event) httpSession.getAttribute("event");
System.out.println((Event) httpSession.getAttribute("event"));
return new SuccessResponse<>(participantService.getParticipants("ALL", event.getId()));
}
【问题讨论】:
-
你调用端点的方式完全一样吗?
标签: java rest spring-boot api httpsession