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

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

 更新時(shí)間:2022年05月28日 15:42:31   作者:把蘋果咬哭的測(cè)試筆記  
這篇文章主要為大家介紹了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ù)庫(kù),直接存放一些靜態(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ù)庫(kù)的交互:

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

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

controller 包下新建 EmployeeController 類:

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

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

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

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

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

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

相關(guān)文章

最新評(píng)論

浪卡子县| 鄯善县| 高邮市| 敦化市| 丰都县| 隆德县| 永城市| 旬邑县| 绥芬河市| 和平县| 庄河市| 扎赉特旗| 新疆| 九寨沟县| 奎屯市| 邵武市| 丹阳市| 灯塔市| 木里| 福清市| 吴江市| 梨树县| 和政县| 峨边| 凤山县| 慈利县| 屯留县| 朔州市| 渭南市| 汪清县| 桓台县| 原阳县| 应城市| 桃江县| 休宁县| 铜鼓县| 新密市| 资兴市| 乌苏市| 九龙县| 万全县|