SpringBoot员工管理的项目——SpringBoot后台数据库的搭建(课时十四)
在员工管理中我们要了解的一些内容
前端页面展示的一些模板
SpringBoot入门程序操作
员工管理系统的数据库的准备工作
利用Thymeleaf进行页面的首页定制
国际化编码格式的操作
登录功能的实现信息
登录拦截器的页面信息
CRUP的实现
这又是在学习项目要了解的内容 本博客文章讲述的内容在下面
第一部分 模板 已经有人写好的模板 拿到直接用的
x-admin(后台模板,推荐)官网 Xadmin - 管理系统从未如此简单
layUI(推荐)官网 Layui - 经典开源模块化前端 UI 框架
bootstrap 官网 Bootstrap中文网
第二部分 SpringBoot项目搭建
IDEA开始学习的页面首页
上面是对一些文件的操作信息
鼠标单机上张图的第一个创建项目 在门项目中选择如图所示
编写项目的坐标
第三部分 员工管理系统的数据库
在创建的项目的过程中导入一些依赖:在pom.xml文件中
到这个官网中导入以下依赖:https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient/3.1
<!-- 引用jquery的文件依赖-->
<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>jquery</artifactId>
<version>3.6.1</version>
</dependency>
<!--Thymeleaf 说明基于3.0.1 模板引擎-->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<!-- lombok依赖包 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.10</version>
</dependency>
将静态资源导入到项目中去:
如图所示的页面信息
完整的pom.xml文件依赖:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.3</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.spring</groupId> <artifactId>springboot0907-web</artifactId> <version>0.0.1-SNAPSHOT</version> <name>springboot0907-web</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- 引用jquery的文件依赖--> <dependency> <groupId>org.webjars.npm</groupId> <artifactId>jquery</artifactId> <version>3.6.1</version> </dependency> <!--Thymeleaf 说明基于3.0.1 模板引擎--> <dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf-spring5</artifactId> </dependency> <!-- lombok依赖包 --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.16.10</version> </dependency> <dependency> <groupId>org.thymeleaf.extras</groupId> <artifactId>thymeleaf-extras-java8time</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
Java项目的总框架的文件目录
从数据库的dao层开始吧:
package com.spring.springboot0907web.dao;
import com.spring.springboot0907web.pojo.Department;
import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
//部门dao
@Repository
public class DepartmentDao {
//模拟数据库中的数据
private static Map<Integer, Department>departments = null;
static {
departments = new HashMap<Integer, Department>(); //创建一个部门表
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> getDepartments(){
return departments.values();
}
//通过id得到部门
public Department getDepartmentById(Integer id){
return departments.get(id);
}
}
package com.spring.springboot0907web.dao;
import com.spring.springboot0907web.pojo.Department;
import com.spring.springboot0907web.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;
//员工dao
@Repository //被string托管
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","1622840727@qq.com",1,new Department(101,"教学部")));
employees.put(1002,new Employee( 1002,"BB","2622840727@qq.com",0,new Department(102,"市场部")));
employees.put(1003,new Employee( 1003,"CC","4622840727@qq.com",1,new Department(103,"教研部")));
employees.put(1004,new Employee( 1004,"DD","5628440727@qq.com",0,new Department(104,"运营部")));
employees.put(1005,new Employee( 1005,"FF","6022840727@qq.com",1,new Department(105,"后勤部")));
}
//主键自增
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);
}
}
在文章的最后分享一段话:
你所浪费的今天,是昨天死去的人奢望的明天,你所厌恶的现在,要么全力以赴,要么果断放弃。明确的生活态度会让一切变得简单,过多模棱两可,犹豫不决,只会在是非中迷失自我。要记住:种-棵树最好的时间是十年前,其次是现在。每个优秀的人都有一段沉默的时光,那段时光是付出很多努力却得不到结果的日子我管它叫,扎根、沉淀、积累。所以不要着急,
不要老觉得为什么我努力了还是没有效果。好好静下心来,认准一个方向,不断沉淀积累。“不积跬步,无以至千里;不积小流,无成江河。”你只管努力沉淀积累,时间会给你惊喜。