一、创建maven项目,项目结构如图
关于项目的创建这里就不在多做介绍,如有不懂的,可以留言
二、在pom文件中引入所需要的jar
如下是我pom文件引入的jar及详细说明:
mysql
mysql-connector-java
8.0.11
com.alibaba
druid
1.1.12
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.0.0
tk.mybatis
mapper-spring-boot-starter
2.1.5
tk.mybatis
mapper
4.0.3
com.github.pagehelper
pagehelper-spring-boot-starter
1.2.3
org.mybatis.generator
mybatis-generator-core
1.3.7
compile
true
log4j
log4j
1.2.17
org.springframework.boot
spring-boot-devtools
true
org.springframework.boot
spring-boot-starter-thymeleaf
三、配制application.yml文件
server:
port: 8080
# servlet:
# context-path: /store #项目名配
# 配制模板引擎
spring:
thymeleaf:
prefix: classpath:/templates/views/
suffix: .html
mode: HTML5
encoding: UTF-8
servlet:
content-type: text/html
cache: false # 关闭缓存,即时刷新,上线生产环境前改为true
mvc:
static-path-pattern: /static/**
# mysql 属性配置
datasource:
# driver-class-name: com.mysql.jdbc.Driver #1.8前的版本使用
driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://localhost:3306/mh_db_02?useSSL=flase&verifyServerCertificate=false; #本地
url: jdbc:mysql://你的mysql地址:3306/数据名?useSSL=false&useUnicode=true; #服务器
username: 用户名
password: 密码
#为mybatis设置,生产环境可删除
restart:
include:
mapper: /mapper-[\\w-\\.]+jar
pagehelper: /pagehelper-[\\w-\\.]+jar
companycommonlibs: tk/mybatis.*
# companycommonlibs: com.share.store.*
# mybatis 集成相关配置
mybatis:
type-aliases-package: com.share.store.**.domain
mapper-locations: classpath:mapper/**/*Mapper.xml
# mappers 多个接口时逗号隔开(通用mapper配制)
mapper:
mappers:
- com.share.store.utils.MyMapper
not-empty: false
identity: MYSQL
# pagehelper 分页插件配制
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
# log 日志配制
logging:
level:
com.share.store: debug #配制控制台打印sql
注:根据配制文件来配制所需要的文件及创建文件夹
四、Springboot启动类配制
五、完结
启动运行,输入地址访问,大功告成
最后,如果有需要源码的朋友,在评论区留言。
标签:mybaties,mapper,Springboot,spring,layui,boot,mysql,mybatis,com
来源: https://blog.csdn.net/qq_28245087/article/details/87891326