☆ 전체소스 : spring305.zip

 

BoardVO.java

package sp.mvc.board.vo;

 

public class BoardVO {

 private int boardSeq;
 private String boardType;
 private int step;
 private int depth;
 private String title;
 private String content;
 private String ip;
 private String deleteYn;
 private String regiDt;
 private String regiUser;
 private String modiDt;
 private String modiUser;
 
 public int getBoardSeq() {
  return boardSeq;
 }
 public void setBoardSeq(int boardSeq) {
  this.boardSeq = boardSeq;
 }
         

          ......

 

 public String getModiUser() {
  return modiUser;
 }
 public void setModiUser(String modiUser) {
  this.modiUser = modiUser;
 }
 
 @Override
 public String toString() {
  return "BoardVO [boardSeq=" + boardSeq + ", boardType=" + boardType
    + ", step=" + step + ", depth=" + depth + ", title=" + title
    + ", content=" + content + ", ip=" + ip + ", deleteYn="
    + deleteYn + ", regiDt=" + regiDt + ", regiUser=" + regiUser
    + ", modiDt=" + modiDt + ", modiUser=" + modiUser + "]";
 }
} 

 

BoardController.java

package sp.mvc.board.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import sp.mvc.board.service.BoardService;
import sp.mvc.board.vo.BoardVO;

 

@Controller
public class BoardController {
 
 @Autowired
 private BoardService boardService;
 
 @RequestMapping("/boardDetail.sp") 
 public ModelAndView getDetail(@RequestParam(value="seq", required=false, defaultValue="1") int boardSeq){
  System.out.println("boardSeq : " + boardSeq);
  BoardVO boardDetail = boardService.getBoardDetail(boardSeq);
  
  System.out.println("boardDetail : " + boardDetail.toString());

  
  ModelAndView modelAndView = new ModelAndView("board/boardDetail");
  modelAndView.addObject("boardDetail", boardDetail);
  return modelAndView;
 }
}

 

BoardServiceImpl.java

package sp.mvc.board.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import sp.mvc.board.dao.BoardDao;
import sp.mvc.board.vo.BoardVO;

 

@Component
public class BoardServiceImpl implements BoardService {

 

 @Autowired
 private BoardDao boardDao;
 
 @Override
 public BoardVO getBoardDetail(int boardSeq) {
  // TODO Auto-generated method stub
  return boardDao.getBoardDetail(boardSeq);
 }

}

 

BoardDaoImpl.java

package sp.mvc.board.dao;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import sp.mvc.board.vo.BoardVO;

 

public class BoardDaoImpl extends SqlMapClientDaoSupport implements BoardDao {

 @Override
 public BoardVO getBoardDetail(int boardSeq) {
  // TODO Auto-generated method stub
  BoardVO boardDetail = (BoardVO)getSqlMapClientTemplate().queryForObject("board.selectBoardDetail", boardSeq);
  
  return boardDetail;
 }

}

 

LogAspect.java

package sp.mvc.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

 

@Aspect
public class LogAspect {

 

 @Pointcut(value="execution(* sp.mvc..*.*(..))")
 public void logPrint(){};
 
 
 @Before("logPrint()")
 public void beforeLog(JoinPoint joinPoint){
  System.out.println("***** before *****");
  System.out.println("method : " + joinPoint.toShortString());
 }
}

 

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
 
  <display-name>spring305</display-name>

 <filter>
  <filter-name>characterEncodingFilter</filter-name>
  <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  <init-param>
   <param-name>encoding</param-name>
   <param-value>UTF-8</param-value>
  </init-param>
 </filter>

 <filter-mapping>
  <filter-name>characterEncodingFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>


 <!-- 공통 빈 설정 -->
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext.xml</param-value>
 </context-param>
  
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
  
 
 <servlet>
  <servlet-name>spring305</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>
    /WEB-INF/pjt_main_config.xml
   </param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
 </servlet>
 
 <servlet-mapping>
  <servlet-name>spring305</servlet-name>
  <url-pattern>*.sp</url-pattern>
 </servlet-mapping>
 
</web-app>

 

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:p="http://www.springframework.org/schema/p"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd">

 
 <!-- 1. dataSource 생성 -->
 <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  <property name="driverClassName" value="oracle.jdbc.OracleDriver"></property>
  <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl"></property>
  <property name="username" value="ADMIN"></property>
  <property name="password" value="GUEST"></property>
 </bean>


 <!-- 2. ibatis 코딩을 지원해주는 SqlMapClient 빈 생성 -->
 <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
  <property name="dataSource" ref="dataSource"></property>
  <property name="configLocation" value="/WEB-INF/SqlMapConfig.xml"></property>
 </bean>


 <!-- 3. 공통 빈 생성 -->
 
 
</beans>

 

pjt_main_config.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:p="http://www.springframework.org/schema/p"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
 
 <context:annotation-config/>

 <aop:aspectj-autoproxy/>
 <context:component-scan base-package="sp.mvc.board.service"/>
 <context:component-scan base-package="sp.mvc.board.dao"/> 
 <context:component-scan base-package="sp.mvc.board.controller"/>

 
 <!-- bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" p:alwaysUseFullPath="true"/ -->
 <!-- bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" p:alwaysUseFullPath="true"/ --> 
 
  
 <!-- ViewResolver 설정 -->
 <bean id="beanNameViewResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="1"/>
 
 <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
  p:order="2" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"></bean>

 


 <!-- aop setting -->
 <bean id="logAspect" class="sp.mvc.aop.LogAspect"></bean>
 
 
 <!-- 각종 bean 설정 -->
 <bean id="boardDao" class="sp.mvc.board.dao.BoardDaoImpl">
  <property name="sqlMapClient" ref="sqlMapClient"></property>
 </bean>

</beans>

 

SqlMapConfig.xml

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMapConfig     
    PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"     
    "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">

 

<sqlMapConfig>

 <settings useStatementNamespaces="true"/>

   <sqlMap resource="/query/board/board.xml"/>

</sqlMapConfig>

 

board.xml

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMap     
    PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"     
    "http://ibatis.apache.org/dtd/sql-map-2.dtd">

 

<!-- Mapper 파일 -->

<!--
 이름 충돌을 방지하기 위해 namespace를 사용
 SqlMapConfig.xml에 <settings useStatementNamespaces="true"/> 설정이 지정되어 있는 경우
 sql구문을 찾을 때 반드시 namespace값을 포함해야 한다.
-->
<sqlMap namespace="board">

 <resultMap id="r_boardVo" class="sp.mvc.board.vo.BoardVO">
  <result property="boardSeq" column="BOARD_SEQ"/>
  <result property="boardType" column="BOARD_TYPE"/>
  <result property="step" column="STEP"/>
  <result property="title" column="TITLE"/>
  <result property="content" column="CONTENT" jdbcType="CLOB"/>
  <result property="ip" column="IP"/>
  <result property="deleteYn" column="DELETE_YN"/>
  <result property="regiDt" column="REGI_DT"/>
  <result property="regiUser" column="REGI_USER"/>
  <result property="modiDt" column="MODI_DT"/>
  <result property="modiUser" column="MODI_USER"/>
  <result property="depth" column="DEPTH"/>
 </resultMap>


 <select id="selectBoardDetail" parameterClass="int" resultMap="r_boardVo">
  <![CDATA[
  SELECT  BOARD_SEQ, BOARD_TYPE, STEP, TITLE, CONTENT, IP, DELETE_YN,
    TO_CHAR(REGI_DT, 'YYYY-MM-DD') AS REGI_DT, REGI_USER,
    TO_CHAR(MODI_DT, 'YYYY-MM-DD') AS MODI_DT, MODI_USER, DEPTH
  FROM BOARD
  WHERE BOARD_SEQ = #value#
  ]]>
 </select>


</sqlMap>

 

 

결과 

요청 URL

   http://localhost:8090/spring305/boardDetail.sp?seq=157

 

***** before *****
method : execution(BoardController.getDetail(..))
boardSeq : 157
***** before *****
method : execution(BoardService.getBoardDetail(..))
***** before *****
method : execution(BoardDao.getBoardDetail(..))
boardDetail : BoardVO [boardSeq=157, boardType=001, step=1, depth=1, title=테스트 입니다.., content=테스트 입니다.
ㅎㅎㅎㅎ
ㅁㅁㅁㅁ
 TEST TEST TEST TEST TEST, ip=127.0.0.1, deleteYn=N, regiDt=2012-03-01, regiUser=ADMIN, modiDt=2012-03-01, modiUser=ADMIN]

 

 

 

+ Recent posts