1. src/main/java/com.spring.board.controller/BoardController.java 클래스에 있는 view() 메서드에 아래 소스코드로 수정 합니다.

@RequestMapping("/view.do")
public String view(Model model, int no){
model.addAttribute("view",boardViewService.service(no));
return "view";
}//method view()




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

   BoardViewService.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 BoardViewService {
private BoardDao boardDao;
@Autowired
public void setBoardDao(BoardDao boardDao) {
this.boardDao=boardDao;
}//method setBoardDao()
public Board service(int no){
return boardDao.view(no);
}//method service();
}//class BoardListService












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

// 게시판 글 보기
public Board view(int no) {
System.out.println("### BoardDao.view() ###");
return sqlSessionTemplate.selectOne("dao.Board.view", no);
}// view()


4. src/main/java/com.spring.board.controller/BoardController.java 클래스에 있는 생성자에 아래 소스코드로 수정 합니다.


private BoardViewService boardViewService;

@Autowired
public BoardController(BoardListService boardListService,BoardViewService boardViewService) {
this.boardListService=boardListService;
this.boardViewService=boardViewService;
}//생성자

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


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


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

<select id="view" resultType="com.spring.board.model.Board">
select no,title,content,
writer,wdate,hit from board
where no=#{no}
</select>

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

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
글보기 페이지 입니다.
<table>
<tr>
<th>번호</th>
<td>${view.no}</td>
</tr>
<tr>
<th>제목</th>
<td>${view.title}</td>
</tr>
<tr>
<th>내용</th>
<td>${view.content}</td>
</tr>
<tr>
<th>작성자</th>
<td>${view.writer}</td>
</tr>
<tr>
<th>작성일</th>
<td>
${view.wdate}
</td>
</tr>
<tr>
<th>조회수</th>
<td>${view.hit}</td>
</tr>
<tr>
<td colspan="2">
<button class="btnUpdate">수정</button>
<button class="btnDelete">삭제</button>
<button class="btnList">리스트</button>
</td>
</tr>
</table>
</body>
</html>








8. 서버(tomcat) 실행 후 http://localhost/board/view.do?no=5 URL로 접속




<끝>











Posted by 홍이홍이
,