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

1. http://hongeui.tistory.com/9?category=732702 참고하세요

test01 계정으로 board 테이블 및 board_seq 시퀀스 생성 합니다.

기본 데이터도 insert문을 사용 하여 삽입 합니다.


create table board(
no number(10) primary key, -- 글번호
title varchar2(100) not null, -- 글제목
content varchar2(2000) not null, -- 글내용
writer varchar2(20) not null, -- 작성자
wdate date,
hit number(10) default 0
);
create sequence board_seq;
insert into board(no,title,content,writer,wdate)
values(board_seq.nextval,'첫 번째 글의 제목','첫 번째 글의 내용','작성자1',sysdate);
insert into board(no,title,content,writer,wdate)
values(board_seq.nextval,'두 번째 글의 제목','두 번째 글의 내용','작성자2',sysdate);
insert into board(no,title,content,writer,wdate)
values(board_seq.nextval,'세 번째 글의 제목','세 번째 글의 내용','작성자3',sysdate);
insert into board(no,title,content,writer,wdate)
values(board_seq.nextval,'네 번째 글의 제목','네 번째 글의 내용','작성자4',sysdate);
insert into board(no,title,content,writer,wdate)
values(board_seq.nextval,'다섯 번째 글의 제목','다섯 번째 글의 내용','작성자5',sysdate);
insert into board(no,title,content,writer,wdate)
values(board_seq.nextval,'여섯 번째 글의 제목','여섯 번째 글의 내용','작성자6',sysdate);
insert into board(no,title,content,writer,wdate)
values(board_seq.nextval,'일곱 번째 글의 제목','일곱 번째 글의 내용','작성자7',sysdate);
insert into board(no,title,content,writer,wdate)
values(board_seq.nextval,'여덟 번째 글의 제목','여덟 번째 글의 내용','작성자8',sysdate);
insert into board(no,title,content,writer,wdate)
values(board_seq.nextval,'아홉 번째 글의 제목','아홉 번째 글의 내용','작성자9',sysdate);
insert into board(no,title,content,writer,wdate)
values(board_seq.nextval,'열 번째 글의 제목','열 번째 글의 내용','작성자10',sysdate);
insert into board(no,title,content,writer,wdate)
values(board_seq.nextval,'열 하나 번째 글의 제목','열 하나 번째 글의 내용','작성자11',sysdate);
insert into board(no,title,content,writer,wdate)
values(board_seq.nextval,'열 둘 번째 글의 제목','열 둘 번째 글의 내용','작성자12',sysdate);
insert into board(no,title,content,writer,wdate)
values(board_seq.nextval,'열 셋 번째 글의 제목','열 셋 번째 글의 내용','작성자13',sysdate);
insert into board(no,title,content,writer,wdate)
values(board_seq.nextval,'열 넷 번째 글의 제목','열 넷 번째 글의 내용','작성자14',sysdate);
select * from board;
commit;

 


2. src/main/java에 package 및 class 생성

패키지 명 : com.spring.board.model

클레스 명 : Board

3. Board.java에 아래 소스코드 입력 합니다.

package com.spring.board.model;
public class Board {
private int no;
private String title;
private String content;
private String writer;
private String wdate;
private int hit;
}//class Board

4. 상단에 있는 Source -> Generate Getters and Setters 클릭





Select All 선택 하여 모두 선택 하여 getter / setter 생성 합니다.







5. src/main/java에 package 및 class 생성 및 service() 메서드 추가

패키지 명 : com.spring.board.service

클레스 명 : BoardListService

6. board.xml에 아래 소스코드를 추가 합니다.

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




7. BoardController.java에 아래 소스코드 추가 합니다. 

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

8. src/main/java에 package 및 class 생성 및 list() 메서드 추가

패키지 명 : com.spring.board.dao

클레스 명 : BoardDao


9. board.xml에 아래 소스코드를 추가 합니다.

<bean class="com.spring.board.dao.BoardDao" />



10. BoardController.java에 있는 list() 메서드 아래 소스코드로 수정

@RequestMapping("/list.do")
public String list(Model model) {
model.addAttribute("list",boardListService.service());
return "list";
}//method list()

11. BoardListService.java 아래 소스코드로 수정 합니다.

public class BoardListService {

private BoardDao boardDao;
@Autowired
public void setBoardDao(BoardDao boardDao) {
this.boardDao=boardDao;
}//method setBoardDao()
public List<Board> service(){
return boardDao.list();
}//method service();
}//class BoardListService





12. BoardDao.java 아래 소스코드로 수정 합니다.

package com.spring.board.dao;
import java.util.List;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import com.spring.board.model.Board;
public class BoardDao {
private SqlSessionTemplate sqlSessionTemplate;
@Autowired
public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
this.sqlSessionTemplate = sqlSessionTemplate;
}//method sqlSessionTemplate()
public List<Board> list() {
return sqlSessionTemplate.selectList("dao.Board.list");
}//method list()
}//class BoardDao













13. src/main/resources/mybatis 폴더에 boardDao.xml 파일 생성


14. boardDao.xml 파일에 아래 소스코드 추가 합니다.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="dao.Board">
<!-- resultType은 select 할때만 사용 -->
<select id="list" resultType="com.spring.board.model.Board">
select no,title,writer,wdate,hit
from board
</select>
</mapper>







15. spring-mvc.xml 파일에 아래 소스코드 추가 합니다.

<!-- connection이 있는 dataResouce를 bean으로 등록 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
<property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:orcl" />
<property name="user" value="test01" />
<property name="password" value="test01" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations">
<list>
<value>classpath:/mybatis/boardDao.xml</value>
</list>
</property>
</bean>
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"
destroy-method="clearCache">
<constructor-arg ref="sqlSessionFactory" />
</bean>













16. src/main/webapp/WEB-INF/view 폴더에 있는 

     list.jsp 파일 아래 소스코드로 수정 합니다.


<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!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>
리스트 페이지 입니다.
<table>
<tr>
<th>글번호</th>
<th>제목</th>
<th>작성자</th>
<th>작성일</th>
<th>조회수</th>
</tr>
<c:forEach var="board" items="${list}">
<tr class="dataTr">
<td id="no">${board.no}</td>
<td id="no">${board.title}</td>
<td id="no">${board.writer}</td>
<td id="no">${board.wdate}</td>
<td id="no">${board.hit}</td>
</tr>
</c:forEach>
</table>
</body>
</html>





















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




<끝>

Posted by 홍이홍이
,


8. src/main/webapp/WEB-INF 아래 view 폴더 생성 ->

src/main/webapp/WEB-INF/view 아래 board 폴더 생성 합니다.

board 폴더에 list.jsp / writeForm.jsp /

view.jsp / updateForm.jsp 파일 생성 합니다.


9. BoardController.java에 메서드 생성


























































































































package com.spring.board.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class BoardController {
@RequestMapping("/list.do")
public String list() {
return "list";
}//list()
@RequestMapping("/write.do")
public String writeForm() {
return "writeForm";
}//writeForm()
@RequestMapping("/view.do")
public String view() {
return "view";
}//view()
@RequestMapping("/update.do")
public String updateForm() {
return "updateForm";
}//updateForm()
}//class BoardController
list() / writeForm() / view() / updateForm()


































10. 서버(tomcat) start 후 위 RequestMapping 한 URL로 접속




















<끝>


Posted by 홍이홍이
,