<JSP 정의(helloView.jsp)>

 

 

​<소스코드>

<%@ page language="java" trimDirectiveWhitespaces="true" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%-- ▼ taglib --%>
<%@ include file="/include/taglibs.inc.jsp"%>
<%-- ▲ taglib --%>
<html>
<head>
<title>Spring 3.0 MVC : Hello World</title>
</head>
<body>
<p>모델에 저장되어 있는 값을 읽기</p>
<ul>
    <li>message1=${message1}</li>
    <li>message1(커스텀 태그 이용)=<c:out value="${message1}" /></li>
    <li>message2=${message2}</li>
    <li>currentDate(포맷)=<fmt:formatDate value="${currentDate}" pattern="yyyy年MM月dd日" /></li>
</ul>
</body>
</html>

 

​​​​​

 

 

 

 

 


<컨트롤러 작성>

 

<소스코드>

import java.util.Date;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
 
/**
 * 간단 컨트롤러
 */
@Controller
모델(값을 유지하는 클래스) 작성
public class HelloWorldController {    
    @RequestMapping("/hello")
    public ModelAndView helloWorld() {
       
        ModelAndView mav = new ModelAndView("/helloView");
       
        // 직접 모델에 메시지 설정
        mav.addObject("message1", " Hello World, <strong>Srping MVC 3.0!</strong> ");
       
        // 모델을 취득해서 메시지 설정
        mav.getModelMap().put("message2", "메시지2");
       
        mav.addObject("currentDate", new Date());


    굵은부분 = [ 모델 (값을 유지핳는 클래스) 작성]

        
        return mav;
    }
}


 

 

 

 


 

 

 

 

 

 


『 Spring MVC용 설정파일 』

​<소스코드>

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    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/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-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">

</beans>

 

 


 

 

 

 

 

 

 

 

 


『 ApplicationContext.xml 』

​<소스코드>

<!– Scan대상 패키지 정의        
Scan대상 어노테이션:@Component, @Repository, @Service, or @Controller. -->

<context:component-scan base-package=“oraclejava.service" />

 


 

 

 

 



『 ApplicationContext.xml 』

​<소스코드>

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basenames">
            <list>
                <value>classpath:message/message</value>
<value>classpath:message/label</value>             </list>
        </property>
    </bean>


 

 

 

 

 

 


『 ApplicationContext.xml 』

​<소스코드>

 

<!– Autowired Scan 유효화 정의 -->
    <context:annotation-config />
    <!-- 설정값 -->
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:database.properties</value>
<value>classpath:app.properties</value>             </list>
        </property>
    </bean>


 

 

 

 

 


『 ApplicationContext.xml 』

​<소스코드>

​<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"     xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-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
    ">


</beans>
 

 

 

 

 



『 Web.xml(Spring MVC Bean 취득) 』

​<소스코드>

<servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>


 

 

 


 

+ Recent posts