1. src/main/java에 있는 com.spring.board.service패키지에

   BoardUpdateService.java 클래스 생성 및 소스코드 추가 합니다.

1
2
3
4
5
6
7
8
9
    private BoardDao boardDao;
    @Autowired
    public void setBoardDao(BoardDao boardDao) {
        this.boardDao = boardDao;
    }//setBoardDao()
 
    public void service(Board board) {
        boardDao.update(board);
    }//service()
cs


2. src/main/java/com.spring.board.controller/BoardController.java 클래스에 있는  생성자및 updateForm()/update() 메서드에 아래 소스코드로 수정 합니다.

1
2
3
4
5
6
7
8
9
10
    private BoardUpdateService boardUpdateService;
    
    @Autowired
    public BoardController(BoardListService boardListService,BoardViewService boardViewService,
            BoardWriteService boardWriteService, BoardUpdateService boardUpdateService) {
        this.boardListService=boardListService;
        this.boardViewService=boardViewService;
        this.boardWriteService=boardWriteService;
        this.boardUpdateService=boardUpdateService;
    }//생성자
cs


1
2
3
4
5
6
7
8
9
10
11
    @RequestMapping(value="/update.do",method=RequestMethod.GET)
    public String updateForm(Model model,int no){
        model.addAttribute("view",boardViewService.service(no));
        return "updateForm";
    }//method updateForm()-GET
    
    @RequestMapping(value="/update.do",method=RequestMethod.POST)
    public String update(Board board){
        boardUpdateService.service(board);
        return "redirect:view.do?no="+board.getNo();
    }//method update()-POST
cs


3. src/main/resources/board.xml 파일에 아래 소스코드 추가 합니다.


<bean class="com.spring.board.service.BoardUpdateService" />


4. src/main/java/com.spring.board.dao/BoardDao.java 클래스에 있는 update() 메서드 생성 및 아래 소스코드로 수정 합니다.


1
2
3
4
5
    // 게시판 글 수정
    public void update(Board board) {
        System.out.println("### BoardDao.update() ###");
        sqlSessionTemplate.update("dao.Board.update", board);
    }//method update()
cs

5. src/main/resources/mybatis/boardDao.xml에 아래 소스코드 추가

1
2
3
4
    <update id="update">
        update board set title=#{title},content=#{content},
        writer=#{writer} where no=#{no}
    </update>
cs


6. src/main/webapp/WEB-INF/view/updateForm.jsp 파일에 아래 소스코드 추가 합니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
글수정 페이지 입니다.
<form action="update.do" method="post">
<input type="hidden" name="no" value="${view.no}" />
제목: <input name="title"  value="${view.title}"/><br/>
내용: <textarea rows="5" cols="60" name="content" >${view.content}</textarea><br/>
작성자: <input name="writer"  value="${view.writer}" readonly="readonly"/><br/>
<button type="submit">수정</button>
<button type="button" class="btnCancel">취소</button>
</form>
</body>
</html>
cs


7. 서버(tomcat) 실행 후 http://localhost/board/view.do?no=1 URL로 접속 합니다.


1번글 글보기 화면 입니다.

1번글 수정 페이지 입니다.


제목과 내용을 수정 후 수정 버튼 클릭 합니다.


1번글 글보기 페이지에 접속 해보면 수정 되어 있는것을 확인 할 수 있습니다.








<끝>


Posted by 홍이홍이
,