1
0
mirror of https://gitee.com/coder-xiaomo/java-note synced 2025-01-10 19:48:15 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
程序员小墨 2022-01-20 16:25:13 +08:00
parent 5f257ea712
commit e17ab2eb94
2 changed files with 65 additions and 9 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -659,15 +659,7 @@ src/main/resources/applicationContext.xml
>
> 添加完后重启idea即可
##### 配置SpringMVC
###### 导入依赖
- spring-context
- spring-jdbc
- spring-
接下来,[配置SpringMVC](#配置SpringMVC)
@ -4116,6 +4108,70 @@ public class UserService {
##### 配置SpringMVC
###### 导入依赖
> 所需依赖导入spring-webmvc就可包含以下四个依赖
>
> - spring-context
> - spring-jdbc
> - spring-web
> - spring-webmvc
导入spring-webmvc依赖
https://mvnrepository.com/artifact/org.springframework/spring-webmvc/5.2.19.RELEASE
```xml
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.19.RELEASE</version>
</dependency>
```
###### 创建SpringMVC配置文件
在resources目录下创建名为spring-servlet.xml文件使用spring模板并修改头部+配置
src/main/resources/spring-servlet.xml
```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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
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
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 声明注解配合 IOC -->
<context:annotation-config></context:annotation-config>
<!-- 扫描注解的包 -->
<context:component-scan base-package="org.example.web"></context:component-scan>
</beans>
```
> 右上角点一下Create new application context
>
> ![image-20220120161453418](张博凯的Java学习笔记.assets/image-20220120161453418.png)
添加mvc命名空间
#### Thymeleaf
> 模板引擎