mirror of
https://gitee.com/coder-xiaomo/java-note
synced 2025-09-06 20:01:39 +08:00
4
This commit is contained in:
@@ -4172,6 +4172,8 @@ src/main/resources/spring-servlet.xml
|
|||||||
|
|
||||||
> SpringMVC提供了一个名为DispatcherServlet的类(前端控制器),用于拦截用户请求交由SpringMVC来处理
|
> SpringMVC提供了一个名为DispatcherServlet的类(前端控制器),用于拦截用户请求交由SpringMVC来处理
|
||||||
|
|
||||||
|
src/main/webapp/WEB-INF/web.xml
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||||
@@ -4265,6 +4267,48 @@ public class UserController {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### 静态资源配置
|
||||||
|
|
||||||
|
> 静态资源:就是项目中的HTML, CSS, JS, 图片, 字体等
|
||||||
|
|
||||||
|
###### /* 和 / 的区别
|
||||||
|
|
||||||
|
src/main/webapp/WEB-INF/web.xml中url-pattern内部配置
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<servlet-mapping>
|
||||||
|
<!-- 两者的区别 -->
|
||||||
|
<url-pattern>/</url-pattern>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
```
|
||||||
|
|
||||||
|
> **/*** 拦截所有的HTTP请求,包括jsp的请求,都作为控制器类的请求路径来处理
|
||||||
|
>
|
||||||
|
> **/** 拦截所有的HTTP请求,但不包括jsp的请求,不会放行静态资源的请求(html、css、js)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
###### 静态资源放行
|
||||||
|
|
||||||
|
在SpringMVC的配置文件中,添加以下代码
|
||||||
|
|
||||||
|
src/main/webapp/WEB-INF/web.xml
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<!-- 请求数据访问 -->
|
||||||
|
<mvc:default-servlet-handler></mvc:default-servlet-handler>
|
||||||
|
|
||||||
|
<!-- 配置静态资源放行 -->
|
||||||
|
<mvc:resources mapping="/css/**" location="/css/"></mvc:resources>
|
||||||
|
<mvc:resources mapping="/js/**" location="/js/"></mvc:resources>
|
||||||
|
<mvc:resources mapping="/images/**" location="/images/"></mvc:resources>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#### Thymeleaf
|
#### Thymeleaf
|
||||||
|
|
||||||
> 模板引擎
|
> 模板引擎
|
||||||
|
Reference in New Issue
Block a user