1:静态资源

下载静态资源:https://files.cnblogs.com/files/applesnt/ztzy.zip

项目下载:https://files.cnblogs.com/files/applesnt/hellospringboot.zip

把css、js、img文件夹放在static目录下

把index.html、list.html、dashboard.html、404.html放在templates目录下

2:pom文件初始配置

<?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> <!--父项目 springboot版本-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <!--项目坐标:gav-->
<groupId>com.springboot</groupId>
<artifactId>hellospringboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>hellospringboot</name>
<description>Demo project for Spring Boot</description> <!--jdk版本-->
<properties>
<java.version>1.8</java.version>
</properties> <!--环境依赖-->
<dependencies> <!--web环境依赖,会自动装配tomcat、静态资源目录、templates目录-->
<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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency> <!--热部署插件-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency> <!--@ConfigurationProperties注解防变红-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency> <!--thymeleaf模板支持-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency> <!--lombok支持-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency> </dependencies> <!--maven打包插件-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>

3:application.yml文件初始配置

server:
port: 80 #访问端口 spring:
thymeleaf:
cache: false #开发时关闭缓存,不然没法看到实时页面
prefix: classpath:/templates/ #文件存放路径
suffix: .html #文件后缀
encoding: utf-8
mode: HTML5
servlet:
content-type: text/html

4:构建java Bean

com\springboot\vo\Department.java #部门

使用@Data注解 如要安装lombok插件

package com.springboot.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor; /*部门*/
@Data //set get toString
@NoArgsConstructor //无参构造器
@AllArgsConstructor //有参构造器
public class Department { /*部门id*/
private Integer id;
/*部门名称*/
private String departmentName; }

com\springboot\vo\Employee.java #员工

package com.springboot.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date; /*员工*/
@Data //set get toString
@AllArgsConstructor //有参构造器
@NoArgsConstructor //无参构造器
public class Employee { /*员工id*/
private Integer id;
/*员工姓名*/
private String lastName;
/*邮箱*/
private String email;
/*性别 0:女 1:男*/
private Integer gender;
/*部门*/
private Department department;
/*生日*/
private Date birth;
}

5:构建模拟数据

com\springboot\dao\DepartmentDao.java #构建部门数据

package com.springboot.dao;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import com.springboot.vo.Department;
import org.springframework.stereotype.Repository; /*把部门dao注入spring容器*/
@Repository
public class DepartmentDao { private static Map<Integer, Department> departments = null;
/*模拟部门表 数据库数据*/
static{
departments = new HashMap<Integer, Department>(); departments.put(101, new Department(101, "D-AA"));
departments.put(102, new Department(102, "D-BB"));
departments.put(103, new Department(103, "D-CC"));
departments.put(104, new Department(104, "D-DD"));
departments.put(105, new Department(105, "D-EE"));
} /*查询所有部门*/
public Collection<Department> getDepartments(){
return departments.values();
} /*通过id查询部门*/
public Department getDepartment(Integer id){
return departments.get(id);
} }

com\springboot\dao\EmployeeDao.java #构建员工数据

package com.springboot.dao;

import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.springboot.vo.Department;
import com.springboot.vo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository; @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, "E-AA", "aa@163.com", 1, new Department(101, "D-AA"),new Date()));
employees.put(1002, new Employee(1002, "E-BB", "bb@163.com", 1, new Department(102, "D-BB"),new Date()));
employees.put(1003, new Employee(1003, "E-CC", "cc@163.com", 0, new Department(103, "D-CC"),new Date()));
employees.put(1004, new Employee(1004, "E-DD", "dd@163.com", 0, new Department(104, "D-DD"),new Date()));
employees.put(1005, new Employee(1005, "E-EE", "ee@163.com", 1, new Department(105, "D-EE"),new Date()));
} private static Integer initId = 1006; /*添加员工*/
public void save(Employee employee){
if(employee.getId() == null){
employee.setId(initId++);
} employee.setDepartment(departmentDao.getDepartment(employee.getDepartment().getId()));
employees.put(employee.getId(), employee);
} /*查询所有员工*/
public Collection<Employee> getAll(){
return employees.values();
} /*通过id查询员工*/
public Employee get(Integer id){
return employees.get(id);
} /*删除员工*/
public void delete(Integer id){
employees.remove(id);
}
}

6:目录结构

Springboot:员工管理之环境准备(十(1))的更多相关文章

  1. Springboot:员工管理之国际化(十(3))

    1:IDEA编码设置UTF-8 2:创建国际化文件 i18n\login.properties #默认语言 i18n\login_en_US.properties #英文语言 i18n\login_z ...

  2. Springboot:员工管理之首页(十(2))

    访问首页可以通过两种方式: 1:编写controller 2:自定义扩展视图解析器(推荐使用) 1:编写Controller com\springboot\controller\IndexContro ...

  3. Springboot:员工管理之公共页面提取 高亮显示(十(5))

    把顶部和左侧的公共代码分别放到header.html和left.html中 顶部代码:resources\templates\header.html 主内容展示: <!DOCTYPE html& ...

  4. 170707、springboot编程之监控和管理生产环境

    spring-boot-actuator模块提供了一个监控和管理生产环境的模块,可以使用http.jmx.ssh.telnet等拉管理和监控应用.审计(Auditing). 健康(health).数据 ...

  5. 「MySql高级查询与编程」练习:企业员工管理

    题目:企业员工管理 一.语言和环境 1.实现语言:SQL. 2.开发环境:MySQL,navicat for mysql. 二.题目(100分): 1.创建数据库及数据表: (1)创建数据库,名称为d ...

  6. RDIFramework.NET ━ 9.2 员工管理 ━ Web部分

    RDIFramework.NET ━ .NET快速信息化系统开发框架 9.2  员工管理 -Web部分 员工(职员)管理主要是对集团.企事业内部员工进行管理.在后面的章节可以看到有一个用户管理,这两者 ...

  7. 使用Jquery+EasyUI进行框架项目开发案例解说之中的一个---员工管理源代码分享

    使用Jquery+EasyUI 进行框架项目开发案例解说之中的一个 员工管理源代码分享 在開始解说之前,我们先来看一下什么是Jquery EasyUI?jQuery EasyUI是一组基于jQuery ...

  8. 使用Jquery+EasyUI项目开发情况的框架是中评---员工管理源代码共享

    使用Jquery+EasyUI 进行框架项目开发案例解说之中的一个 员工管理源代码分享 在開始解说之前,我们先来看一下什么是Jquery EasyUI?jQuery EasyUI是一组基于jQuery ...

  9. Struts2+Spring+Hibernate实现员工管理增删改查功能(一)之登录功能

    昨天的博客中我分享了个人关于ssh实现员工管理的框架整合,今天我在分享管理员登录功能的实现.  转载请注明出处"http://www.cnblogs.com/smfx1314/p/78013 ...

随机推荐

  1. TensorFlow 中文资源精选,官方网站,安装教程,入门教程,实战项目,学习路径。

    Awesome-TensorFlow-Chinese TensorFlow 中文资源全集,学习路径推荐: 官方网站,初步了解. 安装教程,安装之后跑起来. 入门教程,简单的模型学习和运行. 实战项目, ...

  2. 粒子群优化算法(PSO)之基于离散化的特征选择(FS)(三)

    作者:Geppetto 前面我们介绍了特征选择(Feature Selection,FS)与离散化数据的重要性,总览的介绍了PSO在FS中的重要性和一些常用的方法,介绍了FS与离散化的背景,介绍本文所 ...

  3. [算法]移除指定元素&strSr()的实现

    移除指定元素 题目 给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 val 的元素,并返回移除后数组的新长度. 不要使用额外的数组空间,你必须仅使用 O(1) 额外空间并 原 ...

  4. LeetCode#1047-Remove All Adjacent Duplicates In String-删除字符串中的所有相邻重复项

    一.题目 给出由小写字母组成的字符串 S,重复项删除操作会选择两个相邻且相同的字母,并删除它们. 在 S 上反复执行重复项删除操作,直到无法继续删除. 在完成所有重复项删除操作后返回最终的字符串.答案 ...

  5. [HDU1029]Ignatius and the Princess IV<桶 水题>

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029 题目大意: 多组数据,每组数据先给一个n,然后给n各数字,找出n各数字中出现了至少(n+1)/2 ...

  6. 关于获取tableView中cell数据的处理

    前言           最近在做一个项目的时候遇到了这么一个问题,就是tableview作为一个表单,每一行cell都需要填充一个数据填充完成后再返回到table页面,最后进行总的提交.   解决 ...

  7. SQL Server 创建链接服务器的脚本,自定义链路服务器的简短名称

    USE [master]GO /****** Object:  LinkedServer [SQL01]    Script Date: 2020/4/9 11:51:17 ******/EXEC m ...

  8. 通俗易懂.NET GC垃圾回收机制(适用于小白面试,大牛勿喷)

    情景:你接到xx公司面试邀请,你怀着激动忐忑的心坐在对方公司会议室,想着等会的技术面试.技术总监此时走来,与你简单交谈后.... 技术:你对GC垃圾回收机制了解的怎么样? 你:还行,有简单了解过. 技 ...

  9. 没用过.gitIgnore还敢自称高级开发?

    Git是跟踪项目中所有文件的好工具, 但是,您会希望在项目的整个生命周期中不要跟踪某些文件及其变化. 系统文件(i.e. Mac系统的.Ds_Store) 应用程序配置文件(i.e. app.conf ...

  10. Linux:注册系统服务

    [参考文章]:Systemd 入门教程:实战篇 [参考文章]:linux systemctl命令详解 1. 简介 将程序注册为系统服务后,可通过 systemctl 和 service 系统命令启动, ...