springBoot案例---员⼯管理系统(狂神说)准备⼯作
导⼊静态资源,创建pojo包,编写dao层
员⼯表
//员⼯表
@Data
@NoArgsConstructor
public class Employee {
private Integer id;
private String lastName;
private String email;
private Integer gender; //性别 0 ⼥, 1,男
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.department = department;
this.birth = new Date();
}
}
部门表
//部门表
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Department {
private int id; //部门id
private String departmentName; //部门名字
}
模拟数据库
部门dao:
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,"市场部"));
免费管理系统html模板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){
(id);
}
}
员⼯dao
import com.kuang.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",1,new Department(101,"教
学部"))); employees.put(1002,new Employee( 1002,"BB","2622840727@qq",0,new Department(102,"市场部"))); employees.put(1003,new Employee( 1003,"CC","4622840727@qq",1,new Department(103,"教研部"))); employees.put(1004,new Employee( 1004,"DD","5628440727@qq",0,new Department(104,"运营部"))); employees.put(1005,new Employee( 1005,"FF","6022840727@qq",1,new Department(105,"后勤部"))); }
//主键⾃增
private static Integer ininId = 1006;
//增加⼀个员⼯
public void save(Employee employee){
Id() == null){
employee.setId(ininId++);
}
employee.Department().getId()));
employees.Id(),employee);
}
//查询全部的员⼯
public Collection<Employee>getALL(){
return employees.values();
}
//通过id查询员⼯
public Employee getEmployeeById(Integer id){
(id);
}
/
/删除⼀个员通过id
public void delete(Integer id){
}
}
⾸页实现
引⼊Thymeleaf
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>as</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
编写MyMvcConfig
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index");
registry.addViewController("/index.html").setViewName("index");
registry.addViewController("/main.html").setViewName("dashboard");
}
所有的静态资源都需要使⽤thymeleaf接管:@{}
# 关闭模板引擎的缓存
spring.thymeleaf.cache=false
t-path=/chang
国际化:
在IDEA中统⼀设置properties的编码
在resources资源⽂件下新建⼀个i18n⽬录,存放国际化配置⽂件;建⽴⼀个login.properties⽂件,还有⼀个login_zh_CN.properties;
配置这个messages的路径
index.html代码如下:
<!DOCTYPE html>
<html lang="en" xmlns:th="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Signin Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
<!-- Custom styles for this template -->
<link th:href="@{/css/signin.css}" rel="stylesheet">
</head>
<body class="text-center">
<form class="form-signin" th:action="@{/user/login}">
<img class="mb-4" th:src="@{/img/bootstrap-solid.svg}" alt="" width="72" height="72">
<h1 class="h3 mb-3 font-weight-normal" th:text="#{login.tip}">Please sign in</h1>
<!--如果msg的值为空,则不显⽰消息-->
<p th:text="${msg}" th:if="${not #strings.isEmpty(msg)}"></p>
<label class="sr-only" th:text="#{login.username}">Username</label>
<input type="text" name="username" class="form-control" th:placeholder="#{login.username}" required="" autofocus="">
<label class="sr-only" th:text="#{login.password}">Password</label>
<input type="password" name="password" class="form-control" th:placeholder="#{login.password}" required="">
<div class="checkbox mb-3">
<label>
<input type="checkbox" value="remember-me"> [[#{ber}]]
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">[[#{login.btn}]]</button>
<p class="mt-5 mb-3 text-muted"> © 2017-2018</p>
<a class="btn btn-sm" th:href="@{/index.html(l='zh_CN')}">中⽂</a>
<a class="btn btn-sm" th:href="@{/index.html(l='en_US')}">English</a>
</form>
</body>
</html>
根据按钮⾃动切换中⽂英⽂
在Spring中有⼀个国际化的Locale (区域信息对象);⾥⾯有⼀个叫做LocaleResolver (获取区域信息对象)的解析器!编写⼀个处理的组件类
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论