250x250
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- r
- Websocket
- 이력서
- 자바
- oracle
- Python
- 토픽추출
- RESFUL
- 게시판 만들기
- spring MVC(모델2)방식
- 방식으로 텍스트
- Gmarket
- 幼稚园杀手(유치원킬러)
- 파이썬
- test
- word2vec
- 코사인 유사도
- mysql
- pytorch
- 크롤링
- 과학백과사전
- (깃)git bash
- lda
- db
- 네이버뉴스
- jsp 파일 설정
- Topics
- java
- tomoto
- 지마켓
Archives
- Today
- Total
무회blog
spring MVC(모델2)방식,JAVA, MySQL , RESFUL, 게시판 만들기 , 002.01 (컨트롤러) 본문
컨트롤러.002.01
com.board.controller
BoardController.java
package com.board.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.board.domain.BoardVO;
import com.board.mapper.BoardMapper;
@Controller
@RequestMapping("/board")
public class BoardController {
@Autowired
private BoardMapper boardMapper;
//게시글 목록
@RequestMapping(method=RequestMethod.GET)
public ModelAndView list() throws Exception{
List<BoardVO> list = boardMapper.boardList();
return new ModelAndView("boardList","list",list);
}
//게시글 작성 페이지(GET)
@RequestMapping(value="/post",method=RequestMethod.GET)
public ModelAndView writeForm() throws Exception{
return new ModelAndView("boardWrite");
}
//게시글 작성(POST)
@RequestMapping(value="/post",method=RequestMethod.POST)
public String write(@ModelAttribute("BoardVO") BoardVO board) throws Exception{
boardMapper.boardInsert(board);
return "redirect://localhost:8080/board";
}
//게시글 상세
@RequestMapping(value="/{bno}",method=RequestMethod.GET)
public ModelAndView view(@PathVariable("bno") int bno) throws Exception{
BoardVO board = boardMapper.boardView(bno);
boardMapper.hitPlus(bno);
return new ModelAndView("boardView","board",board);
}
//게시글 수정 페이지(GET)
@RequestMapping(value="/post/{bno}", method=RequestMethod.GET)
public ModelAndView updateForm(@PathVariable("bno") int bno) throws Exception{
BoardVO board = boardMapper.boardView(bno);
return new ModelAndView("boardUpdate","board",board);
}
//게시글 수정(PATCH)
@RequestMapping(value="/post/{bno}", method=RequestMethod.PATCH)
public String update(@ModelAttribute("BoardVO")BoardVO board,@PathVariable("bno") int bno) throws Exception{
boardMapper.boardUpdate(board);
return "redirect://localhost:8080/board/"+bno;
}
//게시글 삭제(DELETE)
@RequestMapping(value="/post/{bno}", method=RequestMethod.DELETE)
public String delete(@PathVariable("bno") int bno) throws Exception{
boardMapper.boardDelete(bno);
return "redirect://localhost:8080/board";
}
}
https://private.tistory.com/38?category=655784
Comments