其他分享
首页 > 其他分享> > 2021暑期项目实训之部门Dao层及Vo代码

2021暑期项目实训之部门Dao层及Vo代码

作者:互联网

Dao层:

package com.rjxy.Repository;

import com.rjxy.Entity.Department;
import com.rjxy.Entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface DepartmentRepository extends JpaRepository<Department, Integer> {

    Department findDepartmentById(Integer departmentId);

    Department findDepartmentByName(String departmentName);

    void deleteDepartmentById(Integer departmentId);

    Department findDepartmentByIdAndCompanyId(Integer departmentId,Integer companyId);

    List<Department> findDepartmentsByCompanyId(Integer companyId);

    Department findDepartmentByNameAndCompanyId(String departmentName,Integer companyId);

}

Vo类:

将部门信息封装好返回给前端

package com.rjxy.Model;

import com.rjxy.Entity.Company;
import com.rjxy.Entity.Department;
import com.rjxy.Entity.User;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@Data
public class DepartmentVo {

    private Integer id;

    private String name;

    private String founderName;

    private Integer companyId;

    private String companyName;

    public static DepartmentVo setDepartment(Department department) {
        DepartmentVo dv = new DepartmentVo();
        dv.setId(department.getId());
        dv.setName(department.getName());
        return dv;
    }

    public static DepartmentVo getDepartment(Department department, Company founder) {
        DepartmentVo dv = new DepartmentVo();
        dv.setId(department.getId());
        dv.setName(department.getName());
        dv.setFounderName(founder.getName());
        return dv;
    }

    public DepartmentVo setDepartmentVo(Department department) {
        setId(department.getId());

        setName(department.getName());

        return this;
    }

    public DepartmentVo setDepartmentVo(Department department,Company company) {
        setDepartmentVo(department);
        if (company != null) {
            setCompanyId(company.getId());
            setCompanyName(company.getName());
        }

        return this;
    }

}

标签:dv,DepartmentVo,Dao,Vo,Department,实训,Integer,department,import
来源: https://blog.csdn.net/qq_44475361/article/details/119217688