springboot集成缓存开发

一、搭建基本环境(springboot++springmvc+mybatis)

引入cache、web、mysql、mybatis模块创建工程

导入数据库文件 创建出department和employee表

创建javaBean封装数据

public class Department {
    
    private Integer id;
    private String departmentName;
    
    
    public Department() {
        super();
        // TODO Auto-generated constructor stub
    }
    public Department(Integer id, String departmentName) {
        super();
        this.id = id;
        this.departmentName = departmentName;
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getDepartmentName() {
        return departmentName;
    }
    public void setDepartmentName(String departmentName) {
        this.departmentName = departmentName;
    }
    @Override
    public String toString() {
        return "Department [id=" + id + ", departmentName=" + departmentName + "]";
    }
View Code

整合MyBatis操作数据库

  • 配置数据源信息
spring.datasource.url=jdbc:mysql://localhost:3306/spring_cache
spring.datasource.username=root
spring.datasource.password=123456



mybatis.configuration.map-underscore-to-camel-case=true

logging.level.com.atguigu.cache.mapper=debug

debug=true

spring.redis.host=118.24.44.169
View Code
  • 使用注解版的MyBatis;
//主配置类上配置
//@MapperScan指定需要扫描的mapper接口所在的包
@MapperScan("com.cache.mapper")

二、快速体验缓存

开启基于注解的缓存 @EnableCaching

//主配置类上配置
@EnableCaching








猜你喜欢

转载自www.cnblogs.com/edda/p/13399411.html