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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package com.spring.board.service;
 
import org.springframework.beans.factory.annotation.Autowired;
 
import com.spring.board.dao.BoardDao;
import com.spring.board.model.Board;
 
public class BoardDeleteService {
    
    private BoardDao boardDao;
    @Autowired
    public void setBoardDao(BoardDao boardDao) {
        this.boardDao = boardDao;
    }//setBoardDao()
 
    public void service(int no) {
        boardDao.delete(no);
    }//service()
 
}//class BoardUpdateService
 
cs

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
private BoardDeleteService boardDeleteService;
    
    @Autowired
    public BoardController(BoardListService boardListService,BoardViewService boardViewService,
            BoardWriteService boardWriteService, BoardUpdateService boardUpdateService,
            BoardDeleteService boardDeleteService) {
        this.boardListService=boardListService;
        this.boardViewService=boardViewService;
        this.boardWriteService=boardWriteService;
        this.boardUpdateService=boardUpdateService;
        this.boardDeleteService=boardDeleteService;
    }//생성자
 
    @RequestMapping("/delete.do")
    public String delete(int no){
        boardDeleteService.service(no);
        return "redirect:./list.do";
    }//method delete()
cs


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


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


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

1
2
3
4
5
    // 게시판 글 삭제
    public void delete(int no) {
        System.out.println("### BoardDao.delete() ###");
        sqlSessionTemplate.delete("dao.Board.delete", no);
    }//method delete()
cs


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

1
2
3
    <delete id="delete">
        delete from board where no=#{no}
    </delete>
cs


6. 서버(tomcat) 실행 후 http://localhost/board/list.do URL로 접속 합니다.

16번 글을 삭제 하겠습니다.


7. http://localhost/board/delete.do?no=16 URL로 접속 합니다.

delete는 따로 페이지가 없으므로 list.do로 다시 돌아가도록 하였습니다.


<끝>




Posted by 홍이홍이
,

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 홍이홍이
,

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

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

package com.spring.board.service;
import org.springframework.beans.factory.annotation.Autowired;
import com.spring.board.dao.BoardDao;
import com.spring.board.model.Board;
public class BoardWriteService {
private BoardDao boardDao;
@Autowired
public void setBoardDao(BoardDao boardDao) {
this.boardDao = boardDao;
}//setBoardDao()
public void service(Board board) {
boardDao.write(board);
}//service()
}//class BoardWriteService









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


private BoardWriteService boardWriteService;

@Autowired
public BoardController(BoardListService boardListService,BoardViewService boardViewService,
BoardWriteService boardWriteService) {
this.boardListService=boardListService;
this.boardViewService=boardViewService;
this.boardWriteService=boardWriteService;
}//생성자
@RequestMapping(value="/write.do",method=RequestMethod.GET)
public String writeForm(){
return "writeForm";
}//method write()-GET
@RequestMapping(value="/write.do",method=RequestMethod.POST)
public String write(Board board){
boardWriteService.service(board);
return "redirect:list.do";
}//wethod write()-POST











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


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



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

// 게시판 글 쓰기
public void write(Board board) {
System.out.println("### BoardDao.write() ###");
sqlSessionTemplate.insert("dao.Board.write", board);
}//method write()

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

<insert id="write">
insert into board(no,title,content,writer,wdate)
values(board_seq.nextval,#{title},#{content},#{writer},sysdate)
</insert>

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


<form action="write.do" method="post">
제목: <input name="title" /><br/>
내용: <textarea rows="5" cols="60" name="content"></textarea><br/>
작성자: <input name="writer" /><br/>
<button type="submit">쓰기</button>
</form>

7. 서버(tomcat) 실행 후 http://localhost/board/write.do URL로 접속 합니다. 제목 / 내용 / 작성자 입력 후 쓰기 버튼 클릭 하면 자동으로 list.do 페이지로 이동 합니다.


<끝>


Posted by 홍이홍이
,