springboot--3--集成mybatis和redis template

1mybatis

1引入Mybatis–starter

<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>

2在application.properties中配置数据源:(原理可参考我的第一篇springboot原理文章):

spring.datasource.url=jdbc:mysql://localhost:3306/course?serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

3在启动类上加mapperScan

@MapperScan(basePackages = {"com.example.demo.dao"})

4在dao层加@mapper扫描即可

redis

1pom.xml:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

2配置数据源:

spring.redis.host=localhost
spring.redis.port=6379

3直接用@Autowired注入redisTemplate即可,springboot会自动配置

注意点,只能用redisTemplate
redisTemplate至于如何序列化,请参考下面的文章:
springboot集成redis

你可能感兴趣的:(springboot--3--集成mybatis和redis template)