发布于2021-05-29 22:46 阅读(969) 评论(0) 点赞(17) 收藏(0)
狂神的教程中的模板资源,自己没有,就在bootstrap模板网站上下载了一个后台管理的模板,用来练手。
https://themefisher.com/free-bootstrap-templates/
https://gridgum.com/themes/category/free/
https://startbootstrap.com/template-categories/all/
部门
/**
* 部门dao
*/
public class DepartmentDao {
//模拟数据库操作
private static Map<Integer, Department> departmentMap = null;
static {
departmentMap = new HashMap<Integer, Department>();
departmentMap.put(100,new Department(100,"教学部"));
departmentMap.put(101,new Department(101,"教研部"));
departmentMap.put(102,new Department(102,"后勤部"));
departmentMap.put(103,new Department(103,"纪律部"));
departmentMap.put(104,new Department(104,"宣传部"));
departmentMap.put(105,new Department(105,"市场部"));
}
//查找所有的部门
public Collection<Department> getDepartments(){
return departmentMap.values();
}
//根据ID获取当前部门
public Department getDepartmentById(Integer id){
return departmentMap.get(id);
}
}
员工
package com.example.demo.dao;
import com.example.demo.pojo.Department;
import com.example.demo.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* 员工dao
*/
@Repository
public class EmployeeDao {
//模拟数据库操作
private static Map<Integer, Employee> employeeMap = null;
@Autowired
private DepartmentDao departmentDao;
static {
employeeMap = new HashMap<Integer, Employee>();
//这个Department不能通过----departmentDao.getDepartmentById()方法获取,因为static优先加载,departmentDao之后加载,获取不到
employeeMap.put(1,new Employee(1,"陈一","1@qq.com",1,new Department(100,"教学部"),new Date()));
employeeMap.put(2,new Employee(2,"陈二","2@qq.com",0,new Department(101,"教研部"),new Date()));
employeeMap.put(3,new Employee(3,"陈三","3@qq.com",1,new Department(102,"后勤部"),new Date()));
employeeMap.put(4,new Employee(4,"陈四","4@qq.com",0,new Department(103,"纪律部"),new Date()));
employeeMap.put(5,new Employee(5,"陈五","5@qq.com",1,new Department(104,"宣传部"),new Date()));
employeeMap.put(6,new Employee(6,"陈六","6@qq.com",0,new Department(105,"市场部"),new Date()));
}
//初始化Id,用于自增操作
private static Integer initId = 7;
//保存Employee
public void save(Employee e){
if (e == null){
e.setId(initId++);
}
e.setDepartment(departmentDao.getDepartmentById(e.getDepartment().getId()));
employeeMap.put(e.getId(),e);
}
//查找所有的员工信息
public Collection<Employee> getEmployees(){
return employeeMap.values();
}
//根据ID获取员工信息
public Employee getEmployeesById(Integer id){
return employeeMap.get(id);
}
//根据ID删除员工
public void removeByID(Integer id){
employeeMap.remove(id);
return;
}
}
所有页面的静态资源都需要使用thymeleaf接管
//全面扩展SpringMVC.
//将这个类变成配置类
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
//视图跳转
//想要通过地址zhaoyun访问到success页面,那么这个页面必须加入<html lang="en" xmlns:th="http://www.thymeleaf.org"> 并且在templates目录下
//跟目录的在这里配置会好一点,但是静态资源加载不到
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index");
}
}
SpringBoot,使用thymeleaf加载不到静态资源。
关注点:
1.自定义的拦截器类:继承WebMvcConfigurer。
2.自定义的拦截器类:加注解@Configuration。
3.自定义的拦截器类:不能加注解@EnableWebMvc。
4.<html lang="en" xmlns:th="http://www.thymeleaf.org">
html标签加上thymeleaf,导入命名空间。
5.link标签改变为:<link th:href="@{/css/monokai.css}" rel="stylesheet">
,th:href以及**@{}**。/就已经能从rescourse目录下查找。
6.thymeleaf可能存在缓存,将缓存设为fasle。
# 关闭模板引擎的缓存
spring:
thymeleaf:
cache: false
@{/}:是万能匹配,即使在配置文件中修改访问路径,依然能找到对应的静态资源。
在配置文件中添加配置:
server:
servlet:
context-path: /zhaoyun
在页面中访问时,能够看到静态资源的加载路径都会自动加上所配置的路径。
作者:听说你很拽
链接:http://www.javaheidong.com/blog/article/207908/4b9207ea063e1f181f9d/
来源:java黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 java黑洞网 All Rights Reserved 版权所有,并保留所有权利。京ICP备18063182号-2
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!