模拟数据源 DAO层

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.zzh.web.dao;

import com.zzh.web.pojo.Department;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

@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,"市场部"));
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();
}

public Department getDepartmentById(Integer id){
return departments.get(id);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.zzh.web.dao;

import com.zzh.web.pojo.Department;
import com.zzh.web.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;

@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", "A123@qq.com", 0, new Department(101, "教学部")));
employees.put(1002, new Employee(1002, "BB", "B123@qq.com", 1, new Department(102, "市场部")));
employees.put(1003, new Employee(1003, "CC", "C123@qq.com", 0, new Department(103, "运营部")));
employees.put(1004, new Employee(1004, "DD", "D123@qq.com", 1, new Department(104, "后勤部")));
employees.put(1005, new Employee(1005, "EE", "E123@qq.com", 0, new Department(105, "教研部")));
}

//自增id
public static Integer initId = 1006;

//增加员工
public void save(Employee employee) {
if (employee.getId() == null) {
employee.setId(initId++);
}
System.out.println("---------------------进行前");
employee.setDepartment(departmentDao.getDepartmentById(employee.getDepartment().getId()));
System.out.println("---------------------进行后");
employees.put(employee.getId(),employee);
}

//查询全部员工信息
public Collection<Employee> getAll() {
return employees.values();
}

//通过id查询员工
public Employee getEmployeeById(Integer id) {
return employees.get(id);
}

public void delete(Integer id){
employees.remove(id);
}
}

1.实体类字段需要与数据库对应

2.实体类的数据类型需要与数据库对应

3.莫名其妙的thymeleaf语法居然可以使用:
th:if=”${dept.getDid()} eq ${emp.getDepartment()}” th:text=”${dept.getDepartmentName()}
这行代码的逻辑为if (a == b) { text = c; }

th:if可能在前端上可以用作if的逻辑判断,没有试过使用其他

1
2
3
4
5
6
7
8
9
10
11
12
    <tr th:each="emp:${emps}">
<td th:text="${emp.getId()}"></td>
<td th:text="${emp.getLastName()}"></td>
<td th:text="${emp.getEmail()}"></td>
<td th:text="${emp.getGender()==1?'男':'女'}"></td>
<td th:each="dept:${departments}" th:if="${dept.getDid()} eq ${emp.getDepartment()}" th:text="${dept.getDepartmentName()}"></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="@{/emp/}+${emp.getId()}">编辑</a>
<a class="btn btn-sm btn-danger" th:href="@{/deleteEmp/}+${emp.getId()}">删除</a>
</td>
</tr>

shiro安全框架的使用

filterMap.put(“/emp”,”perms[user:add]”);前面一个参数需要的是RequestMapping里面的跳转路径,得到的是那个路径下的Controller操作以及数据。

anon:无需认证就可以访问
authc:必须认证了才能访问
user:必须拥有记住我功能才能使用
perms:拥有对某个资源的权限才能访问
role:拥有某个角色权限才能访问
logout:注销

doGetAuthenticationInfo:认证
doGetAuthentizationInfo:授权

表对应类
字段对应属性
行记录对应对象