springboot集成缓存开发

时间:2020-07-29 21:30:03   收藏:0   阅读:73

一、搭建基本环境(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
//主配置类上配置
//@MapperScan指定需要扫描的mapper接口所在的包
@MapperScan("com.cache.mapper")

 

 

 

二、快速体验缓存

开启基于注解的缓存 @EnableCaching

//主配置类上配置
@EnableCaching

 









评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!