@Slf4j
@RequiredArgsConstructor
@Controller
@RequestMapping("/board")
public class BoardController {
private final BoardService service;
@PreAuthorize("hasRole('MEMBER')")
@GetMapping("/register")
public void registerForm(Model model, @AuthenticationPrincipal CustomUser customUser) throws Exception {
Member member = customUser.getMember();
log.info("registerForm member.getUserId() = " + member.getUserId());
Board board = new Board();
board.setWriter(member.getUserId());
model.addAttribute(board);
}
...
@PreAuthorize("(hasRole('MEMBER') and principal.username == #writer) or hasRole('ADMIN')")
@PostMapping("/remove")
public String remove(int boardNo, RedirectAttributes rttr, String writer) throws Exception {
service.remove(boardNo);
rttr.addFlashAttribute("msg", "SUCCESS");
return "redirect:/board/list";
}
@PreAuthorize("hasRole('MEMBER') and principal.username == #board.writer")
@PostMapping("/modify")
public String modify(Board board, RedirectAttributes rttr) throws Exception {
service.modify(board);
rttr.addFlashAttribute("msg", "SUCCESS");
return "redirect:/board/list";
}
}