springmvc注解demo01

1.需要的jar包

2.springmvc.xml配置

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
 4     xmlns:context="http://www.springframework.org/schema/context"
 5     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
 6     xsi:schemaLocation="http://www.springframework.org/schema/beans 
 7         http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
 8         http://www.springframework.org/schema/mvc 
 9         http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
10         http://www.springframework.org/schema/context 
11         http://www.springframework.org/schema/context/spring-context-3.1.xsd 
12         http://www.springframework.org/schema/aop 
13         http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
14         http://www.springframework.org/schema/tx 
15         http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
16         <!-- 默认注册了注解映射器和注解适配器等bean -->
17         <!-- 扫描包下的注解 -->
18         <context:component-scan base-package="com.jove"></context:component-scan>
19         <!-- 处理器映射器,处理器适配器 默认对json格式数据的支持 -->
20         <mvc:annotation-driven/>
21         <!-- 视图解析器 -->
22         <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
23             <property name="prefix" value="/WEB-INF/jsps/"></property>
24             <property name="suffix" value=".jsp"></property>
25         </bean>
26 </beans>

2.web.xml配置

 1 <!DOCTYPE web-app PUBLIC
 2  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 3  "http://java.sun.com/dtd/web-app_2_3.dtd" >
 4 
 5 <web-app>
 6     <display-name>Archetype Created Web Application</display-name>
 7     <!-- 字符编码过滤器 -->
 8     <filter>
 9         <filter-name>character</filter-name>
10         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
11         <init-param>
12             <param-name>encoding</param-name>
13             <param-value>UTF-8</param-value>
14         </init-param>
15     </filter>
16     <filter-mapping>
17         <filter-name>character</filter-name>
18         <url-pattern>/*</url-pattern>
19     </filter-mapping>
20     <!-- 加载springmvc.xml -->
21     <servlet>
22         <servlet-name>springmvc</servlet-name>
23         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
24         <init-param>
25             <param-name>contextConfigLocation</param-name>
26             <param-value>classpath:/config/springMVC.xml</param-value>
27         </init-param>
28     </servlet>
29     <servlet-mapping>
30         <servlet-name>springmvc</servlet-name>
31         <url-pattern>*.do</url-pattern>
32     </servlet-mapping>
33 
34 </web-app>

 

posted on 2018-01-08 13:12  jovelove  阅读(95)  评论(0)    收藏  举报