1
2 3 xmlns="http://java.sun.com/xml/ns/javaee"
4 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
5 id="WebApp_ID" version="2.5">
6
7
8
9 HiddenHttpMethodFilter
10 class>org.springframework.web.filter.HiddenHttpMethodFilterclass>
11
12
13 HiddenHttpMethodFilter
14 /*
15
16
17
18
19 springDispatcherServlet
20 org.springframework.web.servlet.DispatcherServlet
21
22 contextConfigLocation
23 classpath:springmvc.xml
24
25 1
26
27
28
29
30 springDispatcherServlet
31 /
32
33
1
2 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xmlns:c="http://www.springframework.org/schema/c"
5 xmlns:aop="http://www.springframework.org/schema/aop"
6 xmlns:cOntext="http://www.springframework.org/schema/context"
7 xmlns:mvc="http://www.springframework.org/schema/mvc"
8 xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
9 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
10 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
11 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">
12
13
14 package="com.springmvc">
15
16
17 class="org.springframework.web.servlet.view.InternalResourceViewResolver">
18
19
20
21
22
23 default-servlet-handler/>
24
25
26
27
1 package com.springmvc.crud.entities;
2
3 import java.util.Date;
4
5 public class Employee {
6
7 private Integer id;
8 private String lastName;
9 private String email;
10 //1 male, 0 female
11 private Integer gender;
12
13 private Date birth;
14 private Float salary;
15
16 public Integer getId() {
17 return id;
18 }
19
20 public void setId(Integer id) {
21 this.id = id;
22 }
23
24 public String getLastName() {
25 return lastName;
26 }
27
28 public void setLastName(String lastName) {
29 this.lastName = lastName;
30 }
31
32 public String getEmail() {
33 return email;
34 }
35
36 public void setEmail(String email) {
37 this.email = email;
38 }
39
40 public Integer getGender() {
41 return gender;
42 }
43
44 public void setGender(Integer gender) {
45 this.gender = gender;
46 }
47
48 public Date getBirth() {
49 return birth;
50 }
51
52 public void setBirth(Date birth) {
53 this.birth = birth;
54 }
55
56 public Float getSalary() {
57 return salary;
58 }
59
60 public void setSalary(Float salary) {
61 this.salary = salary;
62 }
63
64 @Override
65 public String toString() {
66 return "Employee [id=" + id + ", lastName=" + lastName + ", email="
67 + email + ", gender=" + gender
68 + ", birth=" + birth + ", salary=" + salary + "]";
69 }
70
71 public Employee(Integer id, String lastName, String email, Integer gender) {
72 super();
73 this.id = id;
74 this.lastName = lastName;
75 this.email = email;
76 this.gender = gender;
77 }
78
79 public Employee() {
80 }
81 }
1 package com.springmvc.crud.dao;
2
3 import java.util.Collection;
4 import java.util.HashMap;
5 import java.util.Map;
6
7 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.stereotype.Repository;
9
10 import com.springmvc.crud.entities.Employee;
11
12 @Repository
13 public class EmployeeDao {
14
15 private static Map employees=null;
16
17 /*@Autowired
18 private DepartmentDao departmentDao;*/
19
20 static{
21 employees = new HashMap();
22
23 employees.put(1001, new Employee(1001, "E-AA", "aa@163.com", 1));
24 employees.put(1002, new Employee(1002, "E-BB", "bb@163.com", 1));
25 employees.put(1003, new Employee(1003, "E-CC", "cc@163.com", 0));
26 employees.put(1004, new Employee(1004, "E-DD", "dd@163.com", 0));
27 employees.put(1005, new Employee(1005, "E-EE", "ee@163.com", 1));
28 }
29
30 private static Integer initId=1006;
31
32 public void save(Employee employee){
33 if(employee.getId()==null){
34 employee.setId(initId++);
35 }
36 //employee.setDepartment(departmentDao.getDepartment(employee.getDepartment().getId()));
37 employees.put(employee.getId(), employee);
38 }
39
40 public Collection getAll(){
41 return employees.values();
42 }
43 public Employee get(Integer id){
44 return employees.get(id);
45 }
46
47 public void delete(Integer id ){
48 employees.remove(id);
49 }
50
51
52 }
1 package com.springmvc.crud.handler;
2
3 import java.util.Map;
4
5 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.stereotype.Controller;
7 import org.springframework.web.bind.annotation.RequestMapping;
8
9 import com.springmvc.crud.dao.EmployeeDao;
10
11 @Controller
12 public class EmployeeHandler {
13
14 @Autowired
15 private EmployeeDao employeeDao;
16
17 @RequestMapping("/listAll")
18 public String list(Map map){
19 map.put("employees",employeeDao.getAll());
20 return "list";
21 }
22 }
1 <%@ page language="java" cOntentType="text/html; charset=UTF-8"
2 pageEncoding="UTF-8"%>
3 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
4
5
6
7
8
9
10
11
12
13
14 ID |
15 LastName |
16 Email |
17 Gender |
18
19
20
21
22 ${emp.id } |
23 ${emp.lastName } |
24 ${emp.email } |
25 ${emp.gender==0? ‘male‘ : ‘female‘ } |
26
27
28
29
30