We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
模仿AnnouncementController,修改其他controller与service,在controller层进行request model和entity,entity和response model的转换。
AnnouncementController.java
@PostMapping({"", "/"}) public Boolean addAnnouncement(@RequestBody @Validated AddAnnouncementRequest request) { Announcement announcement = request.toAnnouncement(); announcement.setAuthor(userService.getUser()); return announcementService.addAnnouncement(announcement); } @GetMapping({"", "/"}) public List<AnnouncementResponse> getAnnouncementList(@RequestParam(defaultValue = "false") Boolean all) { return AnnouncementResponse.fromAnnouncementList(announcementService.getAnnouncementList(all)); } @GetMapping("/index") public List<AnnouncementDisplayResponse> getIndexAnnouncementList() { return AnnouncementDisplayResponse.fromAnnouncementList(announcementService.getAnnouncementDisplayList()); }
AddAnnouncementRequest.java
@Data public class AddAnnouncementRequest { @NotBlank(message = "{title cannot be empty}") @NotNull(message = "{title is missing}") private String title; private String content; public Announcement toAnnouncement() { return new Announcement() .setTitle(title) .setContent(content) .setEnabled(true); } }
AnnouncementResponse.java
@Data @Accessors(chain = true) public class AnnouncementResponse { private String id; private String title; private String content; private String userId; private Boolean enabled; private Date createTime; private Date updateTime; public AnnouncementResponse(Announcement announcement) { this.id = announcement.getId(); this.title = announcement.getTitle(); this.content = announcement.getContent(); this.userId = announcement.getAuthor().getId(); this.enabled = announcement.getEnabled(); this.createTime = announcement.getCreateTime(); this.updateTime = announcement.getUpdateTime(); } public static List<AnnouncementResponse> fromAnnouncementList(List<Announcement> announcementList) { return announcementList.stream() .map(AnnouncementResponse::new) .collect(Collectors.toList()); } }
目前涉及到的controller有:RoleController与UserController。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
模仿AnnouncementController,修改其他controller与service,在controller层进行request model和entity,entity和response model的转换。
AnnouncementController.java
AddAnnouncementRequest.java
AnnouncementResponse.java
目前涉及到的controller有:RoleController与UserController。
The text was updated successfully, but these errors were encountered: