单表操作:

# src/main/java/com/wu/dao/DepartmentDao .java

@Repository
public class DepartmentDao {
private static Map<Integer, Department> departments = null; private static Integer initId = 5; static {
departments = new HashMap<Integer, Department>();
departments.put(1, new Department(1, "行政部"));
departments.put(2, new Department(2, "财务部"));
departments.put(3, new Department(3, "运营部"));
departments.put(4, new Department(4, "开发部"));
} public Collection<Department> index() {
return departments.values();
} public void store(Department department) {
department.setId(initId);
departments.put(initId, department);
initId++;
} public Department show(Integer id) {
return departments.get(id);
} public void destroy(Integer id) {
departments.remove(id);
}
}

关联表操作:

# src/main/java/com/wu/dao/EmployeeDao.java

@Repository
public class EmployeeDao {
private static Map<Integer, Employee> employees = null; @Autowired
private DepartmentDao departmentDao; static {
employees = new HashMap<Integer, Employee>();
employees.put(1, new Employee(1, "张三", 3));
employees.put(2, new Employee(2, "李四", 1));
employees.put(3, new Employee(3, "王五", 4));
employees.put(4, new Employee(4, "赵六", 2));
} private static Integer initId = 5; public Collection<Employee> index() {
return employees.values();
} public void store(Employee employee) {
employee.setId(initId);
employees.put(initId, employee);
initId++;
} public Employee show(Integer id) {
Employee employee = employees.get(id);
Integer departmentId = employee.getDepartmentId();
Department department = departmentDao.getDepartment(departmentId);
employee.setDepartment(department);
return employee;
} public void destroy(Integer id) {
employees.remove(id);
}
}

SpringBoot 之 Dao层模拟数据库操作的更多相关文章

  1. iBatis——自动生成DAO层接口提供操作函数(详解)

    iBatis——自动生成DAO层接口提供操作函数(详解) 在使用iBatis进行持久层管理时,发现在使用DAO层的updateByPrimaryKey.updateByPrimaryKeySelect ...

  2. Spring框架针对dao层的jdbcTemplate操作crud之update修改数据库操作

    使用jdbcTemplate 原理是把加载驱动Class.forName("com.mysql.jdbc.Driver"); 和连接数据库Connection conn=Drive ...

  3. Spring框架针对dao层的jdbcTemplate操作crud之add添加数据库操作

    使用jdbcTemplate 原理是把加载驱动Class.forName("com.mysql.jdbc.Driver"); 和连接数据库Connection conn=Drive ...

  4. springboot 注册dao层 service 层

    可以使用三种注解来引入DAO层的接口到spring容器中.1.@Mapper,写在每一个DAO层接口上,如下: 2.@MapperScan和@ComponentScan两者之一.前者的意义是将指定包中 ...

  5. Spring框架针对dao层的jdbcTemplate操作crud之query查询数据操作

    查询目标是完成3个功能: (1)查询表,返回某一个值.例如查询表中记录的条数,返回一个int类型数据 (2)查询表,返回结果为某一个对象. (3)查询表,返回结果为某一个泛型的list集合. 一.查询 ...

  6. Spring框架针对dao层的jdbcTemplate操作crud之delete删除数据库操作 Spring相关Jar包下载

    首先,找齐Spring框架中IoC功能.aop功能.JdbcTemplate功能所需的jar包,当前13个Jar包 1.Spring压缩包中的四个核心JAR包,实现IoC控制反转的根据xml配置文件或 ...

  7. Spring框架针对dao层的jdbcTemplate操作之jdbc数据库连接原始操作方法 所需安装包下载

    crud指数据库或者持久层的基本操作,包括 增加(Create).读取查询(Retrieve 取回).更新(Update)和删除(Delete) Spring不仅对JDBC进行了封装,也对Hibern ...

  8. node14---分层结构数据库操作

    /**回调函数(函数作为参数): 0. 外层函数调用的地方,一定是外层函数体先执行,回调函数和普通函数地址一样,然后看函数体规定回调函数怎么执行. 1. 异步时候使用回调函数, 无论是否异步,回调函数 ...

  9. Spring框架针对dao层的jdbcTemplate操作crud之query查询数据操作 —— 查询表,返回结果为对象的list集合

    用JdbcTemplate的方法完成, 查询数据库表,把用户表sw_user所有数据以List<User>集合返回 在JdbcTemplateDemo类中增加查询返回所有对象集合的方法qu ...

随机推荐

  1. 【Services】【Web】【tomcat】配置tomcat支持https传输

    1. 基础: 1.1. 描述:内网的tomcat接到外网nginx转发过来的请求之后需要和外网的客户端进行通讯,为了保证通讯内容的安装,使用tomcat使用https协议. 1.2. 链接:http: ...

  2. 【Linux】【Commands】systemd

    1. 系统启动流程:POST --> Boot Sequeue(BIOS) --> Bootloader(MBR) --> Kernel(ramdisk) --> rootfs ...

  3. profile的使用详解

    前言 在开发过程中,我们的项目会存在不同的运行环境,比如开发环境.测试环境.生产环境,而我们的项目在不同的环境中,有的配置可能会不一样,比如数据源配置.日志文件配置.以及一些软件运行过程中的基本配置, ...

  4. 4.Vue.js-起步

    Vue.js 起步 每个 Vue 应用都需要通过实例化 Vue 来实现. 语法格式如下: var vm = new Vue({ // 选项 }) 接下来让我们通过实例来看下 Vue 构造器中需要哪些内 ...

  5. Mysql配置文件 4c8g优化

    目录 一.说明 二.配置 一.说明 以下配置适合4核8G及以下的配置,会让性能稍微提高1/3左右. 测试语句 mysqlslap -uroot -p123456 --concurrency=100 - ...

  6. 为什么重写equals()就要重写hashcode()

    阿里巴巴开发规范 只要重写 equals,就必须重写 hashCode 因为 Set 存储的是不重复的对象,依据 hashCode 和 equals 进行判断,所以 Set 存储的对象必须重写这两个方 ...

  7. 【分布式技术专题】「OSS中间件系列」Minio的文件服务的存储模型及整合Java客户端访问的实战指南

    Minio的元数据 数据存储 MinIO对象存储系统没有元数据数据库,所有的操作都是对象级别的粒度的,这种做法的优势是: 个别对象的失效,不会溢出为更大级别的系统失效. 便于实现"强一致性& ...

  8. Linux(Centos)安装git

    直接使用yum源安装git 安装的版本是1.8.3.1 yum install -y git 安装完成后,查看版本 [root@master ~]# git --version git version ...

  9. 【LeetCode】404. Sum of Left Leaves 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目大意 题目大意 解题方法 递归 迭代 日期 [LeetCode] 题目地址:h ...

  10. 【LeetCode】375. Guess Number Higher or Lower II 解题报告(Python)

    [LeetCode]375. Guess Number Higher or Lower II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...