| 13 | import java.util.*; |
| 14 | |
| 15 | @Controller |
| 16 | @RequestMapping("/board") |
| 17 | public class BoardController { |
| 18 | @Autowired |
| 19 | BoardService boardService; |
| 20 | |
| 21 | @PostMapping("/modify") |
| 22 | public String modify(BoardDto boardDto, SearchCondition sc, RedirectAttributes rattr, Model m, HttpSession session) { |
| 23 | String writer = (String)session.getAttribute("id"); |
| 24 | boardDto.setWriter(writer); |
| 25 | |
| 26 | try { |
| 27 | if (boardService.modify(boardDto)!= 1) |
| 28 | throw new Exception("Modify failed."); |
| 29 | |
| 30 | rattr.addFlashAttribute("msg", "MOD_OK"); |
| 31 | return "redirect:/board/list"+sc.getQueryString(); |
| 32 | } catch (Exception e) { |
| 33 | e.printStackTrace(); |
| 34 | m.addAttribute(boardDto); |
| 35 | m.addAttribute("msg", "MOD_ERR"); |
| 36 | return "board"; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | @GetMapping("/write") |
| 41 | public String write(Model m) { |
| 42 | m.addAttribute("mode", "new"); |
| 43 | |
| 44 | return "board"; |
| 45 | } |
| 46 | |
| 47 | @PostMapping("/write") |
| 48 | public String write(BoardDto boardDto, RedirectAttributes rattr, Model m, HttpSession session) { |
| 49 | String writer = (String)session.getAttribute("id"); |
| 50 | boardDto.setWriter(writer); |
| 51 | |
| 52 | try { |
| 53 | if (boardService.write(boardDto) != 1) |
| 54 | throw new Exception("Write failed."); |
| 55 | |
| 56 | rattr.addFlashAttribute("msg", "WRT_OK"); |
| 57 | return "redirect:/board/list"; |
| 58 | } catch (Exception e) { |
| 59 | e.printStackTrace(); |
| 60 | m.addAttribute(boardDto); |
| 61 | m.addAttribute("mode", "new"); |
| 62 | m.addAttribute("msg", "WRT_ERR"); |
| 63 | return "board"; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | @GetMapping("/read") |
| 68 | public String read(Integer bno, SearchCondition sc, RedirectAttributes rattr, Model m) { |
| 69 | try { |
| 70 | BoardDto boardDto = boardService.read(bno); |
| 71 | m.addAttribute(boardDto); |
| 72 | } catch (Exception e) { |
nothing calls this directly
no outgoing calls
no test coverage detected