本地安装 Redis
项目结构:
SpringBootRedis 工程项目结构如下:
controller - Controller 层
dao - 数据操作层
model - 实体层
service - 业务逻辑层
Application - 启动类
resources 资源文件夹
application.properties - 应用配置文件,应用启动会自动读取配置
generatorConfig.xml - mybatis 逆向生成配置(这里不是本文只要重点,所以不进行介绍)
mapper 文件夹
StudentMapper.xml - mybatis 关系映射 xml 文件
项目工程代码详情
pom.xml 配置
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.1.7.RELEASE
com.example
demo
0.0.1-SNAPSHOT
war
demo
Demo project for Spring Boot
1.8
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-tomcat
provided
org.springframework.boot
spring-boot-starter-test
test
mysql
mysql-connector-java
5.1.46
org.springframework.boot
spring-boot-starter-data-redis
2.1.6.RELEASE
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.3.2
com.google.code.gson
gson
2.8.5
org.springframework.boot
spring-boot-maven-plugin
org.mybatis.generator
mybatis-generator-maven-plugin
1.3.7
${basedir}/src/main/resources/generatorConfig.xml
true
mysql
mysql-connector-java
8.0.15
application.properties 配置
spring:
datasource:
url: jdbc:mysql://localhost:3306/mydb?useSSL=true
username: oukele
password: oukele
driver-class-name: com.mysql.jdbc.Driver
# 配置 redis
redis:
# redis 数据库索引(默认为0)
database: 0
# redis 服务地址
host: 127.0.0.1
# redis 连接端口
port: 6379
# redis 服务器链接密码 (默认为空)
password:
# 连接超时时间 (毫秒)
timeout: 5000
# 配置 redis 连接池
jedis:
pool:
# 连接池最大连接数 (使用负值表示没有限制)
max-active: 8
# 连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1
# 连接池的最大空闲连接
max-idle: 8
# 连接池中 最小空闲连接
min-idle: 0
# 配置 mybatis
mybatis:
# 设置 实体类所在的包名
typeAliasesPackage: com.example.demo.model
# mybatis xml 映射关系
mapper-locations: classpath:mapper/*.xml
项目结构图