最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot模擬員工數(shù)據(jù)庫并實現(xiàn)增刪改查操作

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

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

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層注入數(shù)據(jù):

部門層:

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 {
    //模擬數(shù)據(jù)庫中的數(shù)據(jù)

    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 {

    //模擬數(shù)據(jù)庫中的數(shù)據(jù)
    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);
        
    }
    //查詢?nèi)繂T工
    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 {
    //模擬數(shù)據(jù)庫中的數(shù)據(jù)

    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:總結(jié)

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

相關(guān)文章

  • 解析Java的JNI編程中的對象引用與內(nèi)存泄漏問題

    解析Java的JNI編程中的對象引用與內(nèi)存泄漏問題

    這篇文章主要介紹了Java的JNI編程中的對象引用與內(nèi)存泄漏問題,重點講述了局部和全局引用時一些值得注意的地方,需要的朋友可以參考下
    2015-11-11
  • MyBatis中常見的SQL執(zhí)行方式及其使用方法

    MyBatis中常見的SQL執(zhí)行方式及其使用方法

    MyBatis可能很多人都一直在用,但是MyBatis的SQL執(zhí)行流程可能并不是所有人都清楚了,下面這篇文章主要給大家介紹了關(guān)于MyBatis中常見的SQL執(zhí)行方式及其使用的相關(guān)資料,需要的朋友可以參考下
    2023-09-09
  • 解決cmd執(zhí)行javac報錯:不是內(nèi)部或外部命令,也不是可運行的程序

    解決cmd執(zhí)行javac報錯:不是內(nèi)部或外部命令,也不是可運行的程序

    剛接觸JAVA的新手可能就不知道怎么解決'JAVAC'不是內(nèi)部命令或外部命令,這篇文章主要給大家介紹了關(guān)于解決cmd執(zhí)行javac報錯:不是內(nèi)部或外部命令,也不是可運行的程序的相關(guān)資料,需要的朋友可以參考下
    2023-11-11
  • JAVA文件讀寫操作詳解

    JAVA文件讀寫操作詳解

    這篇文章主要為大家詳細介紹了JAVA文件讀寫操作,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-02-02
  • Java16 JDK安裝并設(shè)置環(huán)境變量的方法步驟

    Java16 JDK安裝并設(shè)置環(huán)境變量的方法步驟

    突然想起自己大學剛接觸java的時候,要下載JDK和配置環(huán)境變量,那時候我上網(wǎng)找了很多教學,本文就詳細的介紹一下Java16 JDK安裝并設(shè)置環(huán)境變量,感興趣的可以了解一下
    2021-09-09
  • java設(shè)計模式--橋接模式詳解

    java設(shè)計模式--橋接模式詳解

    這篇文章主要為大家詳細介紹了java設(shè)計模式之橋接模式,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能給你帶來幫助
    2021-07-07
  • JAVA實現(xiàn)生成順序ID,不浪費ID

    JAVA實現(xiàn)生成順序ID,不浪費ID

    這篇文章主要介紹了JAVA實現(xiàn)生成順序ID,不浪費ID問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-04-04
  • MyBatis與Spring中的SqlSession詳解

    MyBatis與Spring中的SqlSession詳解

    在MyBatis中,你可以使用SqlSessionFactory來創(chuàng)建SqlSession,使用MyBatis-Spring之后,你不再需要直接使用SqlSessionFactory了,接下來通過示例代碼講解MyBatis與Spring中的SqlSession,需要的朋友可以參考下
    2024-05-05
  • SpringMVC詳解如何映射請求數(shù)據(jù)

    SpringMVC詳解如何映射請求數(shù)據(jù)

    這篇文章主要給大家介紹了關(guān)于SpringMvc映射請求數(shù)據(jù)的相關(guān)資料,文中通過實例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2022-06-06
  • Java開發(fā)框架spring實現(xiàn)自定義緩存標簽

    Java開發(fā)框架spring實現(xiàn)自定義緩存標簽

    這篇文章主要介紹了Java開發(fā)框架spring實現(xiàn)自定義緩存標簽的詳細代碼,感興趣的小伙伴們可以參考一下
    2015-12-12

最新評論

万盛区| 虹口区| 濮阳县| 焉耆| 集安市| 乐亭县| 江川县| 塔城市| 汾西县| 招远市| 绥阳县| 思茅市| 太仆寺旗| 南通市| 临颍县| 沙坪坝区| 麻城市| 孟津县| 金乡县| 远安县| 来凤县| 松潘县| 渝北区| 安溪县| 关岭| 德昌县| 古蔺县| 公主岭市| 孝义市| 内乡县| 新闻| 六盘水市| 兰溪市| 绵竹市| 额济纳旗| 五家渠市| 泾川县| 新昌县| 老河口市| 镇雄县| 新安县|