标签:依赖 value 控制器 jsp font cat size web request
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>
web.xml
<!-- springmvc -->
<servlet>
<!-- 注册DispatcherServlet -->
<servlet-name>dispatcherservlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 初始化参数 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<!-- SpringMvc.xml文件的路径 -->
<param-value>classpath:/configuration/SpringMvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<!-- 匹配controller的规则 -->
<servlet-name>dispatcherservlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
springmvc.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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
">
<!-- 开启注解扫描 -->
<context:component-scan base-package="com.gxy.controller"></context:component-scan>
<!-- mvc注解驱动,自动注册MVC依赖的内置bean -->
<mvc:annotation-driven></mvc:annotation-driven>
<!-- 视图解析器 (把逻辑视图解析成物理视图)-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 前缀 -->
<property name="prefix" value="/"></property>
<!-- 后缀 -->
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
Controller.java
//@Controller(功能和@Component一样;但他不仅注册了Bean并且将此类设置成了控制器);
@Controller
public class HelloHandler {
//映射请求地址
@RequestMapping("/index")
public String hello(){
System.out.println("index......");
//return一个页面名字,由视图解析器解析成物理路径;
return "index";
}
}
标签:依赖 value 控制器 jsp font cat size web request
原文地址:https://www.cnblogs.com/loveweni/p/12807555.html