}
}
- EmployeeDao
@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,“AA”,“A123456@qq.com”,1,new Department(101,“教学部”)));
employees.put(1002,new Employee(1002,“BB”,“B123456@qq.com”,0,new Department(102,“市场部”)));
employees.put(1003,new Employee(1003,“CC”,“C123456@qq.com”,1,new Department(103,“教研部”)));
employees.put(1004,new Employee(1004,“DD”,“D123456@qq.com”,0,new Department(104,“运营部”)));
employees.put(1005,new Employee(1005,“EE”,“E123456@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);
}
/**
-
查询全部员工信息
-
@return
*/
public Collection getAll() {
return employees.values();
}
/**
-
通过id查询员工
-
@param id
-
@return
*/
public Employee getEmployeeById(Integer id) {
return employees.get(id);
}
/**
-
删除员工通过id
-
@param id
*/
public void delete(Integer id) {
employees.remove(id);
}
}
================================================================
需要引入模板引擎
org.springframework.boot
spring-boot-starter-thymeleaf
Controller(不建议使用)
@Controller
public class IndexController {
@RequestMapping({“/”,“/index.htm”,“/index.html”})
public String index(){
return “index”;
}
}
自定义配置类
addViewControllers()
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController(“/”).setViewName(“index”);
registry.addViewController(“/index.htm”).setViewName(“index”);
registry.addViewController(“/index.html”).setViewName(“index”);
}
}
- 导入thymeleaf包
- 将所有页面的静态资源使用thymeleaf接管
===