标签:intern drive local res main apt jquery param 映射
<!-- SpringMVC依赖包 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.2.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.2.RELEASE</version>
<scope>compile</scope>
</dependency>
<!-- springMVC核心配置 -->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<!--spingMVC的配置路径 -->
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- 拦截设置 -->
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
其中,spring-mvc.xml文件路径:src\main\resources
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
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-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<!-- 扫描controller(controller层注入)
当配置了它后,Spring会自动的到com.mjl.controller
下扫描带有@controller @service @component等注解等类,将他们自动实例化 -->
<context:component-scan base-package="com.th.*"/>
<!-- 注册HandlerMapper、HandlerAdapter两个映射类,开启注解 -->
<mvc:annotation-driven />
<!-- 静态资源访问(不拦截此目录下的东西的访问) -->
<mvc:resources location="/jslib/img/" mapping="/jslib/img/**" />
<mvc:resources location="/jslib/jquery/" mapping="/jslib/jquery/**" />
<!-- ViewResolver视图解析器,对模型视图添加前后缀 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
<property name="order" value="1" />
</bean>
</beans>
输入地址:http://localhost:8080/tss/th/hello 转到demoMVC.jsp页面
输入地址:http://localhost:8080/tss/th/student 转到stu.jsp页面
项目代码:https://github.com/tianhu9102/tss
标签:intern drive local res main apt jquery param 映射
原文地址:https://www.cnblogs.com/tianhu9102/p/10026291.html