【发布时间】:2019-03-23 19:04:20
【问题描述】:
我试图在https://github.com/callicoder/spring-security-react-ant-design-polls-app 了解全栈网络应用程序的代码 但我不明白 spring-boot 是如何知道当前用户正在登录的。
这是调用 api 的 ReactJS(前端)代码。
export function getUserCreatedPolls(username, page, size) {
page = page || 0;
size = size || POLL_LIST_SIZE;
return request({
url: API_BASE_URL + "/users/" + username + "/polls?page=" + page + "&size=" + size,
method: 'GET'
});
}
而且,这是从前端接收变量的 spring-boot(back-end) 代码
@GetMapping("/users/{username}/polls")
public PagedResponse<PollResponse> getPollsCreatedBy(@PathVariable(value = "username") String username,
@CurrentUser UserPrincipal currentUser,
@RequestParam(value = "page", defaultValue = AppConstants.DEFAULT_PAGE_NUMBER) int page,
@RequestParam(value = "size", defaultValue = AppConstants.DEFAULT_PAGE_SIZE) int size) {
return pollService.getPollsCreatedBy(username, currentUser, page, size);
}
- spring-boot 如何从前端获取 {UserPrincipal currentUser}?
- ReactJs 如何将 {UserPrincipal currentUser} 发送到后端?
【问题讨论】:
标签: spring reactjs spring-boot login-control