Springboot第一个网站

完整项目Gitee仓库地址:https://gitee.com/jacksu1/springboot-employee
网页图片:
在这里插入图片描述
![](https://img-blog.csdnimg.cn/20210508165517489.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0phY2tTdTExMTE=,size_16,color_FFFFFF,t_70#pic_center在这里插入图片描述
#开发心得:
利用课余大概一个月的时间搭建了这个SpringBoot的员工管理平台,跟着狂神的springboot学的,在这之前连造假数据都不会,慢慢还是学了挺多,。session、拦截器、怎么写Controller层、怎么把表单封装给对象然后提交给后端,从后端获取值提交给前端,各个页面的跳转,分割前端的请求提取出字符…说几个我卡得比较久的点吧

##造假数据
在没有数据库的时候如何用假数据来测,这里有个设计思想,就想用list和arrylist的一样,将List emp=new AyyList();在以后要更改arrylist为其他的时候会更方便,同理,用map和hashmap也一样。再就是自增主键和默认时间 new date

public class DepartmentDao {
    //造假数据
    private static Map<Integer, Department> department=null;
    //用类变量stati在类被初始化的时候就开始加载
    static {
        //用Map来模拟表
        department=new HashMap<Integer, Department>();
        department.put(101,new Department(101,"教学部"));
        department.put(102,new Department(102,"市场部"));
        department.put(103,new Department(103,"后勤部"));
        department.put(104,new Department(104,"教研部"));
        department.put(105,new Department(105,"运营部"));

    }

    public Collection<Department> getdepartment(){
        return department.values();
    }
    public Department getdepartmentById(Integer id){
        return department.get(id);
    }

@Repository
public class EmployeeDao {
private static Map<Integer,Employee> employees=null;
//d对于每个员工有所属部门
@Autowired
private DepartmentDao departmentdao=null;

static {
    employees=new HashMap<Integer, Employee>();
    employees.put(1001,new Employee(1001,"苏涛","1765772391@qq.com",0,new Department(101,"教学部")));
    employees.put(1002,new Employee(1002,"AA","1765772391@qq.com",0,new Department(102,"市场部")));
    employees.put(1003,new Employee(1003,"BB","1765772391@qq.com",1,new Department(103,"市场部")));
    employees.put(1004,new Employee(1004,"CC","1765772391@qq.com",0,new Department(104,"教研部")));
    employees.put(1005,new Employee(1005,"DD","1765772391@qq.com",1,new Department(105,"运营部")));

}
@Autowired
private  DepartmentDao departmentDao;
//主键自增
private static Integer initId = 1006;

//增加一个员工
public void save(Employee employee) {
    if (employee.getId() == null) {
        employee.setId(initId++);
    }
    //通过这个员工的编号来获得对应的derpartment
    employee.setDepartment(departmentDao.getdepartmentById(employee.getDepartment().getId()));
    employees.put(employee.getId(),employee);
}
//查询所有员工信息
public Collection<Employee> getAll(){
    return employees.values();
}
//查询一个员工
public Employee getEmployeeById(Integer id){
    return employees.get(id);
}
public  void deleteEmployeeById(Integer id){
    employees.remove(id);
}

}
##thymeleaf中表达式的使用
用来取值的KaTeX parse error: Expected '}', got 'EOF' at end of input: …update/{id}(id={emp.getId()})}**

在这里插入代码片<tr th:each="emp : ${emps}">
									<td th:text="${emp.getId()}"></td>
									<td th:text="${emp.getName()}"></td>
									<td th:text="${emp.getEmail()}"></td>
									<td th:text="${emp.getSex()==0?'女':'男'}"></td>

									<td th:text="${emp.getDepartment().getName()}"></td>
									<td th:text="${#dates.format(emp.getBirth(),'yyyy-MM-dd HH:mm:ss')}"></td>
									<td >
<!--										这里的请求都会背拦截,应该用已有控制类来跳页面-->
										<a class="btn btn-sm btn-primary" th:href="@{/toupdate/{id}(id=${emp.getId()})} ">编辑</a>
										<a class="btn btn-sm btn-danger"th:href="@{/delete/{id}(id=${emp.getId()})}">删除</a>
									</td>

								</tr>
								

##目录结构和各种注解的使用
在这里插入图片描述
##常用的一些配置,和mybatis的使用
最好先用测试类测完之后再用Control层调用,先写mapper接口,注意声明@mapper和@Repository来被spring托管,再在资源目录下仙剑建立mybatis-mapper文件夹,在配置中绑定mapper,头文件,写法。在这里插入图片描述在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值