@3/20/2023
컨트롤러
@GetMapping("/{postId}")
public String viewPost(
@PathVariable Long postId,
@RequestParam(required = false) Long currentPage,
@SessionAttribute User loginUser,
Model model
) {
Post foundPost = postService.findPostById(postId);
postService.addView(foundPost, loginUser);
...
}
Java
복사
서비스
@Transactional
public void addView(Post post, User user) {
if (post.getUser().getId() != user.getId()) {
post.setView(post.getView() + 1);
}
}
Java
복사