码迷,mamicode.com
首页 > 编程语言 > 详细

SpringMVC配置概要

时间:2014-12-20 17:01:34      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:

WEB.xml配置

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

<web-app xmlns="http://java.sun.com/xml/ns/javaee"   

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  

         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   

                             http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"   

         version="2.5" >  

         

<servlet>  

        <servlet-name>springMvc</servlet-name>  

        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  

        <init-param>  

            <param-name>contextConfigLocation</param-name>  

            <param-value>classpath:springMvc-servlet.xml</param-value>  

        </init-param>  

        <load-on-startup>1</load-on-startup>

    </servlet>  

    <servlet-mapping>  

        <servlet-name>springMvc</servlet-name>  

        <url-pattern>/</url-pattern>  

    </servlet-mapping>

</web-app>

Maven配置:

 <dependency>  

        <groupId>org.springframework</groupId>  

        <artifactId>spring-web</artifactId>  

        <version>3.1.1.RELEASE</version>  

        <type>jar</type>  

        <scope>compile</scope>  

    </dependency>  

    <dependency>  

        <groupId>org.springframework</groupId>  

        <artifactId>spring-core</artifactId>  

        <version>3.1.1.RELEASE</version>  

        <type>jar</type>  

        <scope>compile</scope>  

    </dependency>  

    <dependency>  

        <groupId>org.springframework</groupId>  

        <artifactId>spring-webmvc</artifactId>  

        <version>3.1.1.RELEASE</version>  

        <type>jar</type>  

        <scope>compile</scope>  

    </dependency>

SpringMvc-servlet.xml配置

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

<beans xmlns="http://www.springframework.org/schema/beans"   

       xmlns:aop="http://www.springframework.org/schema/aop"   

       xmlns:context="http://www.springframework.org/schema/context"  

       xmlns:mvc="http://www.springframework.org/schema/mvc"   

       xmlns:tx="http://www.springframework.org/schema/tx"   

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  

       xsi:schemaLocation="http://www.springframework.org/schema/aop   

        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd   

        http://www.springframework.org/schema/beans   

        http://www.springframework.org/schema/beans/spring-beans-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/mvc   

        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd   

        http://www.springframework.org/schema/tx   

        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">  

  <mvc:annotation-driven />  

    <context:component-scan base-package="com.springmvc.action" />  

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  

        <property name="prefix" value="/WEB-INF/pages/" />  

        <property name="suffix" value=".jsp" />  

    </bean>  

</beans>  


测试Action代码:

@Controller   

@RequestMapping("/welcome")  

public class HelloWorldController {

@RequestMapping(value="/hello",method = RequestMethod.GET) 

public String printWelcome(ModelMap model) {  

System.out.println("test.i am here");

       model.addAttribute("message", "Spring 3 MVC Hello World");  

       return "index";  

   }

}



SpringMVC配置概要

标签:

原文地址:http://my.oschina.net/u/257950/blog/358355

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!