基本
web.xml
<!-- 配置springMVC -->
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<!-- contextConfigLocation 是固定的 -->
<param-name>contextConfigLocation</param-name>
<!-- 配置读取路径-->
<param-value>classpath*:config/springAnnotation-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<!-- 配置拦截规则-->
<url-pattern>/</url-pattern>
</servlet-mapping>
springAnnotation-servlet.xml
<!-- 注解扫描包 -->
<context:component-scan base-package="com.tgb.web.controller.annotation" />
<!-- 开启注解 -->
<mvc:annotation-driven/>
<!-- 视图解析器-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
浙公网安备 33010602011771号