Add 공시사항 메뉴 추가

This commit is contained in:
Daeil Choi
2023-02-03 15:19:08 +09:00
parent 41c2dc134a
commit 2bd3cf1afd
13 changed files with 279 additions and 57 deletions

View File

@@ -0,0 +1,43 @@
package com.example.springsecuritystudy.notice;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.example.springsecuritystudy.post.PostDto;
import lombok.RequiredArgsConstructor;
@Controller
@RequiredArgsConstructor
@RequestMapping("/notice")
public class NoticeController {
private final NoticeService noticeService;
@GetMapping
public String findByPost(Model model) {
List<Notice> notices = noticeService.findAll();
model.addAttribute("notices", notices);
return "notice/index";
}
@PostMapping
public String savePost(@ModelAttribute PostDto postDto) {
noticeService.saveNotice(postDto.getTitle(), postDto.getContent());
return "redirect:notice";
}
@DeleteMapping
public String deletePost(@RequestParam Long id) {
noticeService.deleteNotice(id);
return "redirect:notice";
}
}