主要用于展示最后的代码。项目结构如下:
1、web.xml<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
(1) bean - Employee
package com.atguigu.rest.bean;public class Employee { private Integer id; private String lastName; private String email; //1 male, 0 female private Integer gender; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public Integer getGender() { return gender; } public void setGender(Integer gender) { this.gender = gender; } public Employee(Integer id, String lastName, String email, Integer gender) { super(); this.id = id; this.lastName = lastName; this.email = email; this.gender = gender; } public Employee() { }}
(2) control - EmployeeControl
package com.atguigu.rest.controller;import com.atguigu.rest.bean.Employee;import com.atguigu.rest.dao.EmployeeDao;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import java.util.Collection;@Controllerpublic class EmployeeController { @Autowired //自动装配:默认根据ByType,其次ByName。在IOC容器的范围内找到一个Bean来赋值 //通过注解 + 扫描,IOC容器中就包含了EmployeeDao这个Bean,从而进行自动装配 private EmployeeDao employeeDao; @RequestMapping(value="/employee", method = RequestMethod.GET) public String getAllEmployee(Model model){ Collection
(3) dao - EmployeeDao
package com.atguigu.rest.dao;import com.atguigu.rest.bean.Employee;import org.springframework.stereotype.Repository;import java.util.Collection;import java.util.HashMap;import java.util.Map;// Dao: 数据访问接口// @Repository持久层注解@Repositorypublic class EmployeeDao { private static Map
(1) employee_add.html
(2) employee_list.html
Employee Info id lastname email gender options(add) delete update
(3) employee_update.html
(4) index.html