redis-cache
1. 依赖
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.1'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'mysql:mysql-connector-java'
annotationProcessor 'org.projectlombok:lombok'
implementation 'org.apache.commons:commons-lang3:3.9'
implementation 'commons-beanutils:commons-beanutils:1.9.3'
compile group: 'tk.mybatis', name: 'mapper-spring-boot-starter', version: '2.1.5'2. 配置
#---mysql---
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/demo?characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=123456
#---mybatis---
mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=com.example.mybatisdemo.po
mybatis.type-handlers-package=com.example.mybatisdemo.typehandler
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.interceptors=
#---mapper---
mapper.mappers=com.example.mybatisdemo.dao.BaseMapper
mapper.not-empty=false
mapper.identity=MYSQL
mapper.enum-as-simple-type=true
#---cache---
spring.cache.cache-names=redisCache
spring.cache.redis.key-prefix=demo:
spring.cache.redis.cache-null-values=true
spring.cache.redis.time-to-live=0ms
spring.cache.redis.use-key-prefix=true
spring.cache.type=REDIS
#---redis---
spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.database=0
spring.redis.jedis.pool.max-active=10
spring.redis.jedis.pool.max-idle=10
spring.redis.jedis.pool.min-idle=5
spring.redis.jedis.pool.max-wait=20003. 启动类
因为我们使用了
tk.mybatis作通用的mapper,这里的MapperScan要使用tk的开启缓存使用
@EnableCaching
4. mybatis日志插件
5. rest
6. dao
7. enum
po里面定义了枚举,json返回的是这个枚举的拼写
8. po
缓存的对象必须实现序列化
9. service
缓存注解中的value就是配置文件中定义的spring.cache.cache-names=redisCache
10. typeHandler
Last updated
Was this helpful?