Springboot:员工管理之环境准备(十(1))
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))的更多相关文章
- Springboot:员工管理之国际化(十(3))
1:IDEA编码设置UTF-8 2:创建国际化文件 i18n\login.properties #默认语言 i18n\login_en_US.properties #英文语言 i18n\login_z ...
- Springboot:员工管理之首页(十(2))
访问首页可以通过两种方式: 1:编写controller 2:自定义扩展视图解析器(推荐使用) 1:编写Controller com\springboot\controller\IndexContro ...
- Springboot:员工管理之公共页面提取 高亮显示(十(5))
把顶部和左侧的公共代码分别放到header.html和left.html中 顶部代码:resources\templates\header.html 主内容展示: <!DOCTYPE html& ...
- 170707、springboot编程之监控和管理生产环境
spring-boot-actuator模块提供了一个监控和管理生产环境的模块,可以使用http.jmx.ssh.telnet等拉管理和监控应用.审计(Auditing). 健康(health).数据 ...
- 「MySql高级查询与编程」练习:企业员工管理
题目:企业员工管理 一.语言和环境 1.实现语言:SQL. 2.开发环境:MySQL,navicat for mysql. 二.题目(100分): 1.创建数据库及数据表: (1)创建数据库,名称为d ...
- RDIFramework.NET ━ 9.2 员工管理 ━ Web部分
RDIFramework.NET ━ .NET快速信息化系统开发框架 9.2 员工管理 -Web部分 员工(职员)管理主要是对集团.企事业内部员工进行管理.在后面的章节可以看到有一个用户管理,这两者 ...
- 使用Jquery+EasyUI进行框架项目开发案例解说之中的一个---员工管理源代码分享
使用Jquery+EasyUI 进行框架项目开发案例解说之中的一个 员工管理源代码分享 在開始解说之前,我们先来看一下什么是Jquery EasyUI?jQuery EasyUI是一组基于jQuery ...
- 使用Jquery+EasyUI项目开发情况的框架是中评---员工管理源代码共享
使用Jquery+EasyUI 进行框架项目开发案例解说之中的一个 员工管理源代码分享 在開始解说之前,我们先来看一下什么是Jquery EasyUI?jQuery EasyUI是一组基于jQuery ...
- Struts2+Spring+Hibernate实现员工管理增删改查功能(一)之登录功能
昨天的博客中我分享了个人关于ssh实现员工管理的框架整合,今天我在分享管理员登录功能的实现. 转载请注明出处"http://www.cnblogs.com/smfx1314/p/78013 ...
随机推荐
- coding++:java-HashMap的负载因子为什么默认是0.75?
本篇文章基于JDK1.8,特在此说明 1):负载因子的作用 负载因子是和扩容机制有关的,意思是如果当前容器的容量,达到了我们设定的最大值,就要开始执行扩容操作.举个例子来解释,避免小白听不懂: 比如说 ...
- Shell 命令 之linux 模式下的编程语言
今天简单介绍一下shell 命令的使用,希望对大家有所帮助!!! 一. 1.首先创建一个文本 在终端 touch test.sh 用gedit test.sh 打开.sh 文件 输入如下,第一行是申明 ...
- Java实现3次找到假球
前言 之前老师让写一个程序,就写了写. 正文 题目要求 程序要求 10个铅球中有一个假球(比其他铅球的重量要轻),用天平三次称出假球. 程序设计思路 第一次使用天平分别称5个球,判断轻的一边有假球:拿 ...
- scikit_learn分类器详解
1 分类 分类是将事物按特性进行分类,例如将手写数字图片分类为对应的数字. 1.1 MINIST数字图片集分类 MINST就是一个70000张规格较小的手写数字图片,如何将他们分类为对应 ...
- Spring Boot整合Thymeleaf视图层
目录 Spring Boot整合Thymeleaf Spring Boot整合Thymeleaf 的项目步骤 Thymeleaf 语法详解 Spring Boot整合Thymeleaf Spring ...
- 《Three.js 入门指南》3.1.1 - 基本几何形状 -圆柱体(CylinderGeometry)
3.1 基本几何形状 圆柱体(CylinderGeometry) 构造函数: THREE.CylinderGeometry(radiusTop, radiusBottom, height, radiu ...
- Java 使用InputStream笔记
当我们要从网络下载资源时,使用类似如下方法来获取InputStream实例: URLConnection connection = new URL("http://www.XXXX.XXX& ...
- java电商项目常见异常
1. java.lang.nullpointerexception 这个异常大家肯定都经常遇到,异常的解释是"程序遇上了空指针",简单地说就是调用了未经初始化的对象或者是不存在的对 ...
- Round 1A 2020 - Code Jam 2020
Problem A. Pattern Matching 把每个字符串分成第一个之前,最后一个之后,中间的部分 三个部分 每个字符串的中间的部分可以直接拼接 前后两个部分需要判断下是否合法 #inclu ...
- [Python] 字符串加密解密
1. 最简单的方法是用base64: import base64 s1 = base64.encodestring('hello world') s2 = base64.decodestring(s1 ...