亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

SpringBoot模擬員工數據庫并實現增刪改查操作

 更新時間:2021年09月20日 11:19:08   作者:夜色架構師  
這篇文章主要給大家介紹了關于SpringBoot模擬員工數據庫并實現增刪改查操作的相關資料,文中通過示例代碼介紹的非常詳細,對大家學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

1:首先創(chuàng)建一個pojo層在里面定義數據

Department部門:

package com.example.springbootweb.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author ${范濤之}
 * @Description
 * @create 2021-09-19 10:25
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Department {
    private  Integer id;
    private String department;
}

Employee部門:

package com.example.springbootweb.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author ${范濤之}
 * @Description
 * @create 2021-09-19 10:26
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Employee {
    private Integer id;
    private  String lastname;
    private  String email;
    private  Integer gender; //0代表女 1代表男
    private  Department department;
    private Data birth;
}

請?zhí)砑訄D片描述

請?zhí)砑訄D片描述

2:編寫dao層注入數據:

部門層:

package com.example.springbootweb.dao;

import com.example.springbootweb.pojo.Department;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ${范濤之}
 * @Description
 * @create 2021-09-19 10:28
 */
//部門dao
public class DepartmentDao {
    //模擬數據庫中的數據

    private  static Map<Integer, Department> department = null;
    static {
        department = new HashMap<Integer,Department>(); //創(chuàng)建一個部門表

        department.put(101,new Department(101,"教學部"));
        department.put(102,new Department(101,"教研部"));
        department.put(103,new Department(101,"市場部"));
        department.put(104,new Department(101,"運營部"));
        department.put(105,new Department(101,"清潔部"));
    }

    //獲得所有部門信息
    public Collection<Department> getDepartment(){

        return  department.values();

    }
    //通過id得到部門
    public  Department getDepartment(Integer id){
        return  department.get(id);

    }

}

請?zhí)砑訄D片描述

員工層:

package com.example.springbootweb.dao;

import com.example.springbootweb.pojo.Department;
import com.example.springbootweb.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ${范濤之}
 * @Description
 * @create 2021-09-19 10:44
 */
@Repository
public class EmployeeDao {

    //模擬數據庫中的數據
    private  static Map<Integer, Employee> employees = null;
    //員工有所屬的部門
    @Autowired
    private  DepartmentDao departmentDao;

    static {
        employees = new  HashMap<Integer,Employee>();

        employees.put(1001,new Employee(1001,"AA","2831826106@qq.com",1,new Department(101,"教學部")));
        employees.put(1002,new Employee(1002,"BB","2831826106@qq.com",1,new Department(101,"教研部")));
        employees.put(1003,new Employee(1003,"CC","2831826106@qq.com",1,new Department(101,"市場部")));
        employees.put(1004,new Employee(1004,"DD","2831826106@qq.com",1,new Department(101,"運營部")));
        employees.put(1005,new Employee(1005,"EE","2831826106@qq.com",1,new Department(101,"清潔部")));

    }
    
    //主鍵自增
    private  static  Integer ininID = 1006;
    // 增加一個員工
    public  void  save(Employee employee){
        if (employee.getId()== null){
            employee.setId(ininID++);
        }
        employee.setDepartment(departmentDao.getDepartmentByid(employee.getDepartment().getId()));
        
        employees.put(employee.getId(),employee);
        
    }
    //查詢全部員工
    public Collection<Employee> getAll(){
        return  employees.values();
    }
    //通過ID查詢員工
    public  Employee getEmployeeByid(Integer id){
        return  employees.get(id);
        
    }
    //刪除員工拖過ID
    public  void  delete(Integer id){
        employees.remove(id);
    }
    


}

部門層

package com.example.springbootweb.dao;

import com.example.springbootweb.pojo.Department;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ${范濤之}
 * @Description
 * @create 2021-09-19 10:28
 */
//部門dao
@Repository
public class DepartmentDao {
    //模擬數據庫中的數據

    private  static Map<Integer, Department> department = null;
    static {
        department = new HashMap<Integer,Department>(); //創(chuàng)建一個部門表

        department.put(101,new Department(101,"教學部"));
        department.put(102,new Department(101,"教研部"));
        department.put(103,new Department(101,"市場部"));
        department.put(104,new Department(101,"運營部"));
        department.put(105,new Department(101,"清潔部"));
    }

    //獲得所有部門信息
    public Collection<Department> getDepartmentByid(){

        return  department.values();

    }
    //通過id得到部門
    public  Department getDepartmentByid(Integer id){
        return  department.get(id);

    }

}

3:總結

到此這篇關于SpringBoot模擬員工數據庫并實現增刪改查操作的文章就介紹到這了,更多相關SpringBoot模擬數據庫增刪改查內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • mybatis注解如何實現對象批量更改

    mybatis注解如何實現對象批量更改

    這篇文章主要介紹了mybatis注解實現對象批量更改的方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • @RequestParam 接收參數的值為null的處理方式

    @RequestParam 接收參數的值為null的處理方式

    這篇文章主要介紹了@RequestParam 接收參數的值為null的處理方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-11-11
  • SpringBoot中集成screw(螺絲釘)實現數據庫表結構文檔生成方法

    SpringBoot中集成screw(螺絲釘)實現數據庫表結構文檔生成方法

    這篇文章主要介紹了SpringBoot中集成screw(螺絲釘)實現數據庫表結構文檔生成,下面以連接mysql數據庫并生成html格式的數據庫結構文檔為例,插件的使用方式除可以使用代碼外,還可以使用Maven插件的方式,需要的朋友可以參考下
    2024-07-07
  • idea hibernate jpa 生成實體類的實現

    idea hibernate jpa 生成實體類的實現

    這篇文章主要介紹了idea hibernate jpa 生成實體類的實現,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-11-11
  • 使用Easyexcel實現不同場景的數據導出功能

    使用Easyexcel實現不同場景的數據導出功能

    這篇文章主要為大家詳細介紹了如何在不同場景下使用Easyexcel實現數據導出功能,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下
    2024-03-03
  • java實現多文件上傳至本地服務器功能

    java實現多文件上傳至本地服務器功能

    這篇文章主要為大家詳細介紹了java實現多文件上傳至本地服務器功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • lambda表達式與傳統接口函數實現方式對比詳解

    lambda表達式與傳統接口函數實現方式對比詳解

    這篇文章主要為大家介紹了lambda表達式與傳統接口函數實現方式對比詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家度偶多進步早日升職加薪
    2022-03-03
  • jmeter調試錯誤全集(入門必備)

    jmeter調試錯誤全集(入門必備)

    在使用jmeter做接口測試的過程中大家是不是經常會遇到很多問題,本文就介紹了jmeter調試錯誤全集,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • Spring依賴注入的三種方式小結

    Spring依賴注入的三種方式小結

    本篇文章主要介紹了Spring依賴注入的三種方式小結,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-08-08
  • Java中的對象和引用詳解

    Java中的對象和引用詳解

    這篇文章主要介紹了Java中的對象和引用詳解的相關資料,需要的朋友可以參考下
    2017-05-05

最新評論