2014년 1월 14일 화요일

D. Spring Framework 게시판 만들기 (코멘트 입력, 출력)-스프링게시판강좌교육

D. Spring Framework 게시판 만들기 (코멘트 입력, 출력)-스프링게시판강좌교육 -유경석

1.     시작하기
 
-       이번에는 게시판 상세보기(글읽기) 페이지에서 게시글에 커멘트를 입력하고, 입력되어 있는 커멘트를  글을 게시글 조회 시 같이 조회될 수 있는 기능을 추가해 보자.


2. [CommentDTO.java]  <---- 만들어야됨.

package com.board.model;

public class CommentDTO {
private String comment_seq;
private String comment_name;
private String comment_comm;
private String seq;
public String getComment_seq() {
return comment_seq;
}
public void setComment_seq(String comment_seq) {
this.comment_seq = comment_seq;
}
public String getComment_name() {
return comment_name;
}
public void setComment_name(String comment_name) {
this.comment_name = comment_name;
}
public String getComment_comm() {
return comment_comm;
}
public void setComment_comm(String comment_comm) {
this.comment_comm = comment_comm;
}
public String getSeq() {
return seq;
}
public void setSeq(String seq) {
this.seq = seq;
}
}

3. [BoardDAO.java] , [BoardDAOImple.java]

package com.board.dao;

import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;

import com.board.model.BoardDTO;
import com.board.model.CommentDTO;

public interface BoardDAO {
// 전체 게시글 수
public int boardCount(Map<String, Object>searchMap)throws DataAccessException;
// 게시판 리스트
public List<BoardDTO> boardList(Map<String, Object>searchMap) throws DataAccessException;
// 게시물 본문 미리보기
public String preView(String seq)throws DataAccessException;
// 게시글 조회수 1씩증가
public int updateReadCount(String seq)throws DataAccessException;
// 게시글 상세보기
public BoardDTO readContent(String seq)throws DataAccessException;
// 코멘트 저장
public int insertComment(CommentDTO commentDTO)throws DataAccessException;
// 코멘트 조회
public List<CommentDTO> ListComment(String seq)throws DataAccessException;
}

----------------------------------------------------------------------------------
package com.board.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import com.board.model.BoardDTO;
import com.board.model.CommentDTO;

public class BoardDAOImple implements BoardDAO {

private JdbcTemplate jdbaTemplate;
public void setDataSource(DataSource dataSource){
this.jdbaTemplate = new JdbcTemplate(dataSource);
}
// 게시글 수
public int boardCount(Map<String, Object>searchMap)throws DataAccessException{
int count = 0;
String sql = "";
if(searchMap.get("boardListSearchText") == null){
sql = "select count(*) from board02";
count = jdbaTemplate.queryForObject(sql,
Integer.class
);
}else{
String boardListSelect = (String) searchMap.get("boardListSelect");
String boardListSearchText = (String) searchMap.get("boardListSearchText");
sql = "select count(*) from board02 where "+boardListSelect+" like '%"+boardListSearchText+"%'";
count = jdbaTemplate.queryForObject(sql,Integer.class);
 
}
return count;
}
// 게시판 리스트
public List<BoardDTO> boardList(Map<String, Object>searchMap) throws DataAccessException {
List<BoardDTO> boardList = null;
String sql = "";
Object[] obj;
if(searchMap.get("boardListSearchText") == null){
sql = "select * from ("
+ " select ROWNUM r, b.seq ,b.name,b.title ,TO_CHAR(b.regdate,'YYYY/MM/DD')as regdate, b.readcount, "
+ "         r.reply_level"
+ " from board02 b, reply r"
+ " where b.seq = r.reply"
+ " order by r.reply desc, r.reply_step asc"
+ " )"
+ " where r BETWEEN ? AND ?";
obj = new Object[] {searchMap.get("startRow"),searchMap.get("endRow")};

}else{
String boardListSelect = (String) searchMap.get("boardListSelect");
String boardListSearchText = (String) searchMap.get("boardListSearchText");
sql = "select * from ("
+ " select ROWNUM r,  b.seq ,b.name,b.title ,TO_CHAR(b.regdate,'YYYY/MM/DD')as regdate, b.readcount, "
+ "         r.reply_level"
+ " from board02 b, reply r"
+ " where b.seq = r.reply"
+ "   and  "+boardListSelect+" like '%"+boardListSearchText+"%'" 
+ " order by r.reply desc, r.reply_step asc"
+ " )"
+ " where r BETWEEN ? AND ?";
 
obj = new Object[] {searchMap.get("startRow"),searchMap.get("endRow")};
}   
boardList = jdbaTemplate.query(sql, 
  obj, 
  new RowMapper<BoardDTO>(){
  public BoardDTO mapRow(ResultSet rs, int rowNum)throws SQLException{
 
  BoardDTO boardDTO = new BoardDTO(rs.getString("seq"),
rs.getString("name"),
rs.getString("title"),
rs.getString("regdate"),
rs.getInt("readcount"),
rs.getInt("reply_level")
  );  
 
  return boardDTO;
  }
});
return boardList;
}
// 게시물 본문내용 미리보기
public String preView(String seq) throws DataAccessException{
String sql = "select content from board02 where seq = ?";
String preContent = "";
Object obj[] = {seq};
preContent = jdbaTemplate.queryForObject(sql,obj,String.class);
return preContent;
}
// 게시글 조회수 1씩증가
public int updateReadCount(String seq)throws DataAccessException{
String sql = " update board02 set readcount = nvl(readcount,0)+1 where seq = ?";
Object[] obj = {seq};
return jdbaTemplate.update(sql,obj);
}
// 게시글 상세보기
public BoardDTO readContent(String seq)throws DataAccessException{
// 조회수 1증가 메소드 호출
this.updateReadCount(seq);
String sql = "select * from board02 where seq = ?";
Object[] obj = {seq};
BoardDTO boardDTO = jdbaTemplate.queryForObject(sql, 
    obj, 
    new RowMapper<BoardDTO>() {
public BoardDTO mapRow(ResultSet rs,int rowNum)throws SQLException {
BoardDTO boardDTO = new BoardDTO();
boardDTO.setSeq(rs.getString("seq"));
boardDTO.setName(rs.getString("name"));
boardDTO.setPasswd(rs.getString("passwd"));
boardDTO.setTitle(rs.getString("title"));
boardDTO.setContent(rs.getString("content"));
boardDTO.setFilename(rs.getString("filename"));
boardDTO.setRegdate(rs.getString("regdate"));
boardDTO.setReadcount(rs.getInt("readcount"));
return boardDTO;
}
});
return boardDTO;
}

// 코멘트 저장
public int insertComment(CommentDTO commentDTO) throws DataAccessException {
String sql = "insert into comment_t02 values(sequence_comment_seq.nextval,?,?,?)";
Object[] obj = {commentDTO.getComment_name(),commentDTO.getComment_comm(),commentDTO.getSeq()};
return jdbaTemplate.update(sql, obj);
}

// 코멘트 조회
public List<CommentDTO> ListComment(String seq) throws DataAccessException {
String sql = "select * from comment_t02 where seq = ?";
Object[] obj = {seq};
List<CommentDTO> list = jdbaTemplate.query(sql, 
   obj,
   new RowMapper<CommentDTO>(){
public CommentDTO mapRow(ResultSet rs,int rowNum)throws SQLException {
CommentDTO commentDTO = new CommentDTO();
commentDTO.setComment_seq(rs.getString("comment_seq"));
commentDTO.setComment_name(rs.getString("comment_name"));
commentDTO.setComment_comm(rs.getString("comment_comm"));
commentDTO.setSeq(rs.getString("seq"));
return commentDTO;
}   
 });
return list;
}
}

4. [BoardService.java] , [BoardServiceImple.java]

package com.board.service;

import java.util.List;
import java.util.Map;

import com.board.model.BoardDTO;
import com.board.model.CommentDTO;

public interface BoardService {

// 게시글 수
public int boardCount(Map<String, Object>searchMap)throws Exception;
// 게시판 리스트
public List<BoardDTO> boardList(Map<String, Object>searchMap)throws Exception;
//게시물 미리보기
public String preView(String seq)throws Exception;

// 게시글 상세보기
public BoardDTO readContent(String seq)throws Exception;
// 코멘트 저장
public int insertComment(CommentDTO commentDTO)throws Exception;
// 코멘트 조회
public List<CommentDTO> ListComment(String seq)throws Exception;
}

--------------------------------------------------------------------------------------
package com.board.service;

import java.util.List;
import java.util.Map;

import com.board.dao.BoardDAO;
import com.board.model.BoardDTO;
import com.board.model.CommentDTO;

public class BoardServiceImple implements BoardService {

private BoardDAO boardDAO;
public void setBoardDAO(BoardDAO boardDAO){
this.boardDAO = boardDAO;
}
// 게시글 수
public int boardCount(Map<String, Object> searchMap) throws Exception {
return boardDAO.boardCount(searchMap);
}

// 게시판 리스트
public List<BoardDTO> boardList(Map<String, Object> searchMap) throws Exception {
return boardDAO.boardList(searchMap);
}
// 게시물 미리보기
public String preView(String seq){
return boardDAO.preView(seq);
}

// 게시글 상세보기
public BoardDTO readContent(String seq)throws Exception{
return boardDAO.readContent(seq);
}

// 코멘트 저장
public int insertComment(CommentDTO commentDTO) throws Exception {
return boardDAO.insertComment(commentDTO);
}

// 코멘트 조회
public List<CommentDTO> ListComment(String seq) throws Exception {
return boardDAO.ListComment(seq);
}

}


 5. [BoardMultiController.java]

package com.onj.board;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.board.model.BoardDTO;
import com.board.model.CommentDTO;
import com.board.service.BoardService;
import com.board.util.EncodingHandler;
import com.board.util.PageHandler;

public class BoardMultiController extends MultiActionController{
private BoardService boardService;
private PageHandler  pageHandler;
public void setBoardService(BoardService boardService){this.boardService = boardService;}
public void setPageHandler(PageHandler pageHandler){this.pageHandler = pageHandler;}
ModelAndView mav = null;
// 게시판 리스트
public ModelAndView list(HttpServletRequest request, HttpServletResponse response)throws Exception{
mav = new ModelAndView();
// 상세보기에서 사용한 session 지운다.
HttpSession session = request.getSession();
if(session.isNew() == false){session.invalidate();}
List<BoardDTO> list = null;
// 검색select , 검색Text
String boardListSelect     = request.getParameter("boardListSelect");  
String boardListSearchText = request.getParameter("boardListSearchText");
Map<String, Object> searchMap = new HashMap<String, Object>();  
 
if(boardListSearchText != null){ 
searchMap.put("boardListSearchText", EncodingHandler.toKor(boardListSearchText));
searchMap.put("boardListSelect", boardListSelect); 
<!-- 잘못된 부분이 있어서 수정하였습니다. -->
mav.addObject("boardListSearchText", EncodingHandler.toKor(boardListSearchText)); 
 mav.addObject("boardListSelect", boardListSelect);
}
String pageNumber = request.getParameter("pageNumber");
int pageNum = 1;
if(pageNumber != null){pageNum = Integer.parseInt(pageNumber);}
// 게시글 수
int totalCount = pageHandler.boardAllNumber(searchMap);
// 페이지 갯수
int totalPageCount = pageHandler.boardPageCount(searchMap);
// startPage , endPage
int startPage = pageHandler.boardStartPage(pageNum);
int endPage   = pageHandler.boardEndPage(pageNum,searchMap);
// 처음, 마지막 rowNumber
List<Object> rowNumberList = new ArrayList<Object>();
rowNumberList = pageHandler.boardSetPageNumber(pageNum);
searchMap.put("startRow", rowNumberList.get(0));
searchMap.put("endRow", rowNumberList.get(1));
// 글 전체 출력
list = boardService.boardList(searchMap);
mav.addObject("pageNumber",pageNum);
mav.addObject("boardCount",totalCount);
mav.addObject("totalPageCount", totalPageCount);
mav.addObject("startPage", startPage);
mav.addObject("endPage", endPage);
mav.addObject("list", list);
mav.setViewName("list");
return mav;
}
// 게시글 상세보기
public ModelAndView read(HttpServletRequest request, HttpServletResponse response)throws Exception{
String seq = request.getParameter("seq");
BoardDTO boardDTO = boardService.readContent(seq);
// 상세글 내용 session에 담음
HttpSession session = request.getSession();
session.setAttribute("boardDTO", boardDTO); 
mav.addObject("boardDto", boardDTO);
mav.addObject("comment", boardService.ListComment(seq));
mav.setViewName("read");
return mav;
}
// 코멘트 저장
public ModelAndView comment(HttpServletRequest request, HttpServletResponse response)throws Exception{
HttpSession session = request.getSession();
BoardDTO boardDTO = (BoardDTO) session.getAttribute("boardDTO");
mav = new ModelAndView("redirect:/read.html?seq="+boardDTO.getSeq());
CommentDTO commentDTO = new CommentDTO();
commentDTO.setComment_name(request.getParameter("comment_name"));
commentDTO.setComment_comm(request.getParameter("comment_comm"));
commentDTO.setSeq(boardDTO.getSeq());
boardService.insertComment(commentDTO);
return mav;
}
}

6. [/WEB-INF/jsp/list.jsp] [/WEB-INF/jsp/read.jsp] , [/js/boardActionJs.js]

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ 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>
 
<link rel="stylesheet" type="text/css" href="/board/css/boardCss.css">

<script type="text/javascript" src="/board/js/boardActionJs.js"></script>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Board Lists</title>
</head>
<body>
<!-- 미리보기 -->
<div id="layer1">
게시물 본문 미리보기
</div>
<center>   
<h1>오엔제이 프로그래밍 실무교육센터 스프링 게시판</h1><hr>
<form name="listForm" method="get">
<table class="listTable">  
<tr> 
<td colspan="5" align="right" id="boardListCount">게시글 수 : ${boardCount} 건</td>
</tr>
</table>
<table class="listTable" border="1" cellpadding="0" cellspacing="0"> 
<tr>
<td>번호</td>
<td>글제목</td>
<td>작성자</td> 
<td>작성일</td>
<td>조회수</td>
</tr>
<tr> 
<c:if var="boardCountZroe" test="${boardCount == 0}">
<td colspan="5">
<font color="red">게시글이 없습니다.</font>
</td>
</c:if>
</tr>
<c:if test="${!boardCountZroe}">
<c:forEach var="list" items="${list}">  
<tr>
<td>${list.seq}</td>
<td>
<a href="/board/read.html?seq=${list.seq}" onmouseover="contentprev('${list.seq}');" onmouseout="hidelayer();">${list.title}</a>
</td>  
<td>${list.name}</td>
<td>${list.regdate}</td>  
<td>${list.readcount}</td>
</tr>
</c:forEach> 
</c:if>
</table>
<!--잘못된 부분이 있어서 수정 하였습니다. -->
<!-- 페이지 -->
<c:if test="${!boardCountZroe}">
<table class="listTable">
<tr>
<td colspan="5" align="center">
<c:if test="${startPage > 1}">
<span>
<a href="/board/list.html?pageNumber=${startPage- 1}&boardListSearchText=${boardListSearchText}&boardListSelect=${boardListSelect}">이전</a>
</span>
</c:if>
<c:forEach var="i" begin="${startPage}" end="${endPage}">
<c:choose>
<c:when test="${pageNumber == i }">
<span>
<a href="/board/list.html?pageNumber=${i}&boardListSearchText=${boardListSearchText}&boardListSelect=${boardListSelect}" id="boardList_a">${i}</a>&nbsp;
</span>
</c:when>
 
<c:otherwise>
<span>
<a href="/board/list.html?pageNumber=${i}&boardListSearchText=${boardListSearchText}&boardListSelect=${boardListSelect}">${i}</a>&nbsp;
</span>
</c:otherwise>
</c:choose>
</c:forEach>
<c:if test="${endPage < totalPageCount}">
<span> 
<a href="/board/list.html?pageNumber=${endPage + 1}&boardListSearchText=${boardListSearchText}&boardListSelect=${boardListSelect}">다음</a>
</span> 
</c:if>
</td>
</tr>
</table>
</c:if>
<!-- 검색 -->
<table class="listTable">
<tr>
<td colspan="5" align="center">
<select name="boardListSelect">
<option value="name">작성자</option>
<option value="title">글제목</option>
<option value="seq">글번호</option>
</select> 
<input type="text" id="boardListSearchText" name="boardListSearchText" onkeydown="enterEvent();"> 
<input type="button" value="검색" onclick="boardListSearchGo();">
/
<input type="button" value="글 입력" onclick="location.href='/board/write.html'"> 
</td> 
</tr>
</table>
</form> 
</center>
</body>
</html>

--------------------------------------------------------------------------------------
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ 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>

<link rel="stylesheet" type="text/css" href="/board/css/boardCss.css">
<script type="text/javascript" src="/board/js/boardActionJs.js"></script>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Board Read</title>
</head>  
<body> 
<center> 
<h1>오엔제이 프로그래밍 실무교육센터 스프링 게시판</h1><hr>
<form name="boardReadForm" method="post">
 
<table id="readTable" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>제목:</td>   
<td class="readTD">${boardDto.title}</td>
</tr>  
<tr>
<td>작성자:</td>
<td class="readTD">${boardDto.name}</td>
</tr> 
<tr>  
<td>내용:</td> 
<td><textarea rows="10" cols="77%" readonly="readonly">${boardDto.content}</textarea></td>
</tr>
<tr>
<td>파일:</td>
<td class="readTD">
<c:choose>
<c:when test="${boardDto.filename != ' '}">
${boardDto.filename}  
</c:when>
<c:when test="${boardDto.filename == ' '}">
파일이 없습니다.
</c:when>
</c:choose>
</td>
</tr>
</table>

<table class="readTable02">
<tr>
<td colspan="2" id="readButtonTD">
<input type="button" value="답변" onclick="location.href='/board/reply.html?seq=${boardDto.seq}'">
<input type="button" value="수정" onclick="location.href='/board/modifyPage.html?seq=${boardDto.seq}'">
<input type="button" value="삭제" onclick="deleteGo('${boardDto.seq}');">
<input type="button" value="목록" onclick="location.href='/board/list.html'">
</td> 
</tr>
</table>
<br>
 
<!-- 코멘트 -->
<table class="readTable02">
<tr> 
<td>이름 : <input type="text" name="comment_name" id="comment_name"></td>
<td>코멘트 : <input type="text" name="comment_comm" id="comment_comm"></td>
<td>  
<input type="button" value="코멘트입력" onclick="commentInput();">
</td>
</tr>
</table>
<br>
<table class="readTable02" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>코멘트 작성자</td>
<td>코멘트 내용</td>
</tr>
</table> 
<table class="readTable02">
<c:forEach var="comment" items="${comment}">
<tr>

<td>${comment.comment_name}</td>
<td>${comment.comment_comm}</td>
</tr> 
</c:forEach> 
</table>
</form>
</center>
</body>
</html>

-------------------------------------------------------------------------------------
  
// 검색 
function boardListSearchGo(){

document.listForm.action ="/board/list.html"; 
document.listForm.submit();
  
// 검색Text입력 후 바로 엔터 가능하게 하는 이벤트
function enterEvent(){
if(window.event.keyCode == 13){
boardListSearchGo();
}
}

// 미리보기(Ajax)
  
var xmlHttp = null;
var xmlDoc  = null;
var message = null;

function createXMLHttpRequest(){

// 익스플로러이면 if 그외 브라우저이면 else
if(window.ActiveXObject){
try{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); // IE 5.0 이하 버전
}catch(e){
try{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); // IE 5.0 이상 버전
}catch(el){xmlHttp = null;}
}
}else if(window.XMLHttpRequest){
try{
xmlHttp = new XMLHttpRequest();
}catch(e){
xmlHttp = null;
}
}
if(xmlHttp == null){errorMessage();}
  
return xmlHttp;
}
 
function errorMessage(){alert("지원할 수 없는 브라우저 입니다.");}


function contentprev(seq){ 
 
var url = "ContentPreview?seq="+seq;
xmlHttp = createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("get",url,true);
xmlHttp.send(null);
}

function handleStateChange(){ 
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){ 
xmlDoc = xmlHttp.responseText; 
document.getElementById("layer1").innerHTML = xmlDoc;
//화면에서 마우스가 움직일때 movetip()함수 발생  
document.onmousemove = movetip;
showlayer();
}
}  
 
// 게시판 글제목에서 마우스가 올라갔을 경우 발생
function showlayer(){
    document.getElementById("layer1").style.visibility="visible";
}
  
// 게시판 글제목에 마우스가 떨어져 있을 경우 발생
function hidelayer(){
    document.getElementById("layer1").style.visibility="hidden";
}

// 미리보기 위치 
function movetip(){
document.getElementById("layer1").style.pixelTop  = event.y+document.body.scrollTop+20;
document.getElementById("layer1").style.pixelLeft = event.x+document.body.scrollLeft+20;
}   


// 코멘트 저장
function commentInput(){
var comment_name = document.getElementById("comment_name");
var comment_comm = document.getElementById("comment_comm");

if(comment_name.value == ""){
alert("코멘트 이름을 적으세요.");
comment_name.focus();
return false;
}
if(comment_comm.value == ""){
alert("코멘트 내용을 적으세요.");
comment_comm.focus();
return false;

boardReadForm.action="/board/comment.html";
boardReadForm.submit();
}

7. [/WEB-INF/spring/appServlet/servlet-context.xml]
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
">
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />

<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<beans:property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<beans:property name="url"      value="jdbc:oracle:thin:@localhost:1521:ex"/>
<beans:property name="username" value="study"/> 
<beans:property name="password" value="study"/>
</beans:bean>
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/jsp/"/>
<beans:property name="suffix" value=".jsp" /> 
</beans:bean>

<!-- 넘어오는 URL에 따라 컨트롤러에서 실행될 메소드 매핑 -->
<!-- PropertiesMethodNameResolver는 prop key로 넘어오는 url에 대해 실행할 컨트롤러의 메소드 정의 -->
<beans:bean id="userControllerMethodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
<beans:property name="mappings">
<beans:props>
<beans:prop key="/list.html">list</beans:prop>
<beans:prop key="/read.html">read</beans:prop>
<beans:prop key="/comment.html">comment</beans:prop>
</beans:props> 
</beans:property>
</beans:bean> 
<!-- controller mapping -->
<beans:bean name="/list.html /read.html /comment.html" class="com.onj.board.BoardMultiController">
<beans:property name="methodNameResolver" ref="userControllerMethodNameResolver"/>
<beans:property name="boardService" ref="boardService"/>
<beans:property name="pageHandler" ref="pageHandler"/>
</beans:bean>
</beans:beans>

댓글 없음:

댓글 쓰기