SpringMVC(三):SpringMVC的两种实现方式
一、方法一:实现Controller接口
这个在我的第一个SpringMVC程序中已经学习过了,在此不作赘述,现在主要来学习第二种方法,使用注解开发;
二、方法二:使用注解开发
1.导包
2.在web.xml中配置DispatcherServlet
3.建立一个Spring配置文件springmvc-servlet.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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--扫描包,使其下的注解生效-->
<context:component-scan base-package="com.jms.controller"/>
<!--让springMVC不处理静态资源-->
<mvc:default-servlet-handler/>
<!--
支持MVC注解驱动
能够帮助我们完成BeanNameUrlHandlerMapping和SimpleControllerHandlerAdapter注入
-->
<mvc:annotation-driven/>
<!--视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="InternalResourceViewResolver">
<!--前缀-->
<property name="prefix" value="/WEB-INF/jsp/"/>
<!--后缀-->
<property name="suffix" value=".jsp"/>
</bean>
</beans>


