【SpringBoot】11、员工管理系统【狂神篇,最全指南

这篇博客详细介绍了如何使用SpringBoot构建员工管理系统,涵盖了国际化设置、首页实现、页面国际化、登录页面处理以及登录拦截器的配置。通过实例代码展示了如何处理登录表单提交、重定向、静态资源过滤以及自定义登录拦截器来保护系统资源。
摘要由CSDN通过智能技术生成

}

}

  • 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);

}

}

4)目录结构


在这里插入图片描述

2、首页实现

================================================================

需要引入模板引擎

org.springframework.boot

spring-boot-starter-thymeleaf

1)方式一


Controller(不建议使用)

@Controller

public class IndexController {

@RequestMapping({“/”,“/index.htm”,“/index.html”})

public String index(){

return “index”;

}

}

2)方式二


自定义配置类

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”);

}

}

3)加载静态资源


  • 导入thymeleaf包
  • 将所有页面的静态资源使用thymeleaf接管

在这里插入图片描述

3、页面国际化

===

  • 9
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值