基于SpringBoot整合Spring、Spring-MVC和Mybatis
基于SpringBoot整合Spring、Spring-MVC和Mybatis
创建新项目myoa
IDEA->new->Project,创建一个SpringBoot项目。
培训pom.xml,在build节点添加下面内容,使得webapp的静态资源能访问
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<!-- 添加访问静态资源文件 -->
<!-- 代码的作用是让src/main/webapp在编译的时候在resoureces路径下也生成webapp的文件 -->
<resources>
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>查看运行结果
集成MyBatis
pom.xml加上MyBatis的依赖
1 | <!-- MyBatis --> |
集成Spring
SpringBoot默认已经集成。
集成SpringMVC
1 | <!-- Spring MVC --> |
集成Logback,统一日志框架
SpringBoot默认已经集成,只需要添加配置文件即可,如果不添加,默认也能打印日志。
logback.xml 极简配置,注意位置是在资源目录
1 | <configuration> |
最终目录
本项目地址
https://github.com/terwer/hoa/tree/myoaboot
Kotlin版本
基于SpringBoot整合Spring、Spring-MVC和Mybatis
https://hexo.terwer.space/post/spring-mvc-mybatis-spring-integration-with-spring-boot.html