操作步骤
- 创建SpringBoot项目
- 配置Mybatis-generator插件
- 构建项目结构
- 配置application.yml或application.properties文件
- 配置generatorConfig.xml文件
- 启动
操作
创建SpringBoot项目
左上角File–>New–>Project…
选择Spring Initializr–>Next
填写好项目信息,点击Next
进入勾选依赖页面,勾选需要的依赖(Spring Web,Mybatis Framework,MySQL Driver),点击Next
填写项目名,点击Finish
项目创建完成
配置Mybatis-genarator插件
找到项目结构下的pom.xml文件,点击查看
在pom.xml文件中找到build标签
下的plugins标签
,在其内添加内容
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
插件配置完成
构建项目结构
构建项目结构,创建项目需要的文件夹以及文件
在代码目录下,创建bean,controller,service,dao等四个文件夹,并在controller文件夹下创建BaseController类
在资源目录下,创建mapper文件夹,创建generatorConfig.xml文件
项目结构构建完成
配置application.yml或application.properties文件
.yml文件配置内容如下:
# 端口配置
server:
port: 8080
spring:
# 模板引擎配置
thymeleaf:
prefix: classpath:/templates/
suffix: .html
mode: HTML
encoding: UTF-8
cache: false
servlet:
content-type: text/html
# 静态文件配置
web:
resources:
static-locations:classpath:/static,classpath:/META-INF/resources,classpath:/templates/
# jdbc配置
datasource:
url: jdbc:mysql://localhost:3306/shopdesign?useUnicode=true&characterEncoding=utf-8
username: root
password: 991218
driver-class-name: com.mysql.jdbc.