最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringMVC?RESTFul實(shí)體類創(chuàng)建及環(huán)境搭建

 更新時(shí)間:2022年05月28日 15:42:31   作者:把蘋果咬哭的測試筆記  
這篇文章主要為大家介紹了SpringMVC?RESTFul實(shí)體類創(chuàng)建及環(huán)境搭建詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

一、搭建 mvc 環(huán)境

新建一個(gè) module 模塊,創(chuàng)建 maven 工程,步驟跟以前一樣,各種配置文件內(nèi)容也可以拷貝修改一下即可。

二、創(chuàng)建實(shí)體類

新建個(gè) bean 包,創(chuàng)建實(shí)體類 Employee:

package com.pingguo.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() {
    }
}

三、準(zhǔn)備 dao 模擬數(shù)據(jù)

新建一個(gè) dao 包,創(chuàng)建 EmployeeDao 類,這里不使用數(shù)據(jù)庫,直接存放一些靜態(tài)數(shù)據(jù):

@Repository
public class EmployeeDao {
    private static Map<Integer, Employee> employees = null;
    static{
        employees = new HashMap<Integer, Employee>();
        employees.put(1001, new Employee(1001, "E-AA", "aa@163.com", 1));
        employees.put(1002, new Employee(1002, "E-BB", "bb@163.com", 1));
        employees.put(1003, new Employee(1003, "E-CC", "cc@163.com", 0));
        employees.put(1004, new Employee(1004, "E-DD", "dd@163.com", 0));
        employees.put(1005, new Employee(1005, "E-EE", "ee@163.com", 1));
    }
    private static Integer initId = 1006;
    public void save(Employee employee){
        if(employee.getId() == null){
            employee.setId(initId++);
        }
        employees.put(employee.getId(), employee);
    }
    public Collection<Employee> getAll(){
        return employees.values();
    }
    public Employee get(Integer id){
        return employees.get(id);
    }
    public void delete(Integer id){
        employees.remove(id);
    }
}

dao 中實(shí)現(xiàn)了幾個(gè)增刪改查的操作,代替與數(shù)據(jù)庫的交互:

  • map集合 employees,里存放了 5 個(gè) Employee 對象。
  • save()方法是保存,包含了添加操作和修改操作。
  • getAll()是查詢所有,返回的是所有 Employee 對象的 value。
  • get()是查詢單個(gè)員工信息,根據(jù) id 。
  • delete()是根據(jù) id 刪除數(shù)據(jù)。

四、準(zhǔn)備控制器

controller 包下新建 EmployeeController 類:

@Controller
public class EmployeeController {
    @Autowired
    private EmployeeDao employeeDao;
}

接下來就可以一個(gè)個(gè)的實(shí)現(xiàn)功能了,大概有:

訪問首頁查詢?nèi)繑?shù)據(jù)刪除跳轉(zhuǎn)到添加數(shù)據(jù)頁面執(zhí)行保存跳轉(zhuǎn)到更新數(shù)據(jù)頁面執(zhí)行更新

  • 訪問首頁
  • 查詢?nèi)繑?shù)據(jù)
  • 刪除
  • 跳轉(zhuǎn)到添加數(shù)據(jù)頁面
  • 執(zhí)行保存
  • 跳轉(zhuǎn)到更新數(shù)據(jù)頁面
  • 執(zhí)行更新

感謝《尚硅谷》的學(xué)習(xí)資源。

以上就是SpringMVC RESTFul實(shí)體類創(chuàng)建及環(huán)境搭建的詳細(xì)內(nèi)容,更多關(guān)于SpringMVC RESTFul實(shí)體類環(huán)境的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論

庄河市| 威海市| 寿阳县| 炉霍县| 许昌县| 会昌县| 古田县| 西丰县| 澎湖县| 隆安县| 凤阳县| 文水县| 祥云县| 孝感市| 大城县| 盐亭县| 浙江省| 台湾省| 抚远县| 监利县| 永川市| 大荔县| 仙桃市| 达州市| 松桃| 三亚市| 台湾省| 闸北区| 海丰县| 新源县| 盖州市| 嵊泗县| 文成县| 栖霞市| 西华县| 儋州市| 大方县| 清涧县| 望城县| 伊春市| 密云县|