springBoot员工管理系统

员工管理系统

1、准备工作

静态资源:链接:https://pan.baidu.com/s/1qtUDuJNVupr872kVDO-veg
提取码:fabo

gitee:https://gitee.com/planting-trees-chen/spring-boot

新建springboot项目

image-20201109155818293

导入jar包

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.12</version>
        <scope>provided</scope>
    </dependency>


    <!--thymeleaf-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>jquery</artifactId>
        <version>3.4.1</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf-spring5</artifactId>
        <version>3.0.9.RELEASE</version>
        <type>pom</type>
    </dependency>

    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-java8time</artifactId>
    </dependency>

</dependencies>

添加静态资源

image-20201109160148706

数据库文件,模拟

实体类Department部门

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Department {
   
    private Integer id;
    private String departmentName;
}

实体类,员工Employee

@Data
@NoArgsConstructor
public class Employee {
   
    private Integer id;
    private String lastName;
    private String email;
    private Integer gender;
    private Department department;
    private Date birth;

    public Employee(Integer id, String lastName, String email, Integer gender, Department department) {
   
        this.id = id;
        this.lastName = lastName;
        this.email = email;
        this.gender = gender;
        this.department = department;
        this.birth = new Date();
    }
}

dao层

//部门dao
@Repository
public class DepartmentDao {
   
    //模拟数据库数据
    private static Map<Integer, Department> departments = null;

    static {
   
        departments = new HashMap<>();
        departments.put(101, new Department(101, "教学部"));
        departments.put(102, new Department(102, "市场部"));
        departments.put(103, new Department(103, "教研部"));
        departments.put(104, new Department(104, "运营部"));
        departments.put(105, new Department(105, "后勤部"));
    }

    //获得所有部门信息
    public Collection<Department> getDepartment() {
   
        return departments.values();
    }

    //通过ID的到部门
    public Department getDepartmentById(Integer id) {
   
        return departments.get(id);
    }
}
//员工dao
@Repository
public class EmployeeDao {
   

    private static Map<Integer, Employee> employees = null;

    //员工所属部门
    @Autowired
    private DepartmentDao departmentDao;

    static {
   
        employees = new HashMap<>();    //创建部门表

        employees.put(1001, new Employee(1001, "AA", "[email protected]", 1, new Department(101, "教学部")));
        employees.put(1002, new Employee(1002, "BB", "[email protected]", 0, new Department(102, "市场部")));
        employees.put(1003, new Employee(1003, "CC", "[email protected]", 1, new Department(103, "教研部")));
        employees.put(1004, new Employee(1004, "DD", "[email protected]", 0, new Department(104, "运营部")));
        employees.put(1005, new Employee(1005, "EE", "[email protected]", 1, new Department(105, "后勤部")));

    }

    //主键自增
    private static Integer initId = 1006;

    //添加员工
    public void save(Employee employee) {
   
        if (employee.getId() == null) {
   
            employee.setId(initId++);
        }
        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);
    }

    //删除
    public void delete(Integer id) {
   
        employees.remove(id);
    }
}

MyMvcConfig配置视图

@Configuration
public class MyMvcConfig implements WebMvcConfigurer 
  • 2
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值