zoukankan      html  css  js  c++  java
  • RESTful

     8. 实例代码

      

        package cn.wolfcode.demo.web.controller;
        
        import cn.wolfcode.demo.domain.Role;
        import org.springframework.stereotype.Controller;
        import org.springframework.web.bind.annotation.*;
        
        import javax.annotation.Generated;
        import java.util.Arrays;
        import java.util.List;
        
        /**
         * 使用RESTful对一个资源增删改查
         */
        @RestController
        @RequestMapping("/employee")
        public class Demo {
            //查询多个
            @GetMapping
            public List<Role> employees(){
                Role role = new Role();
                role.setId(1L);
                role.setName("戴涛");
                role.setSn("daitao");
                return Arrays.asList(role);
            }
        
            //查询单个(使用占位符)
            @GetMapping(value = "/{id}")
            @ResponseBody
            public Role employees(@PathVariable("id") Long id) {
                Role role = new Role();
                role.setId(id);
                role.setName("戴涛");
                role.setSn("daitao");
                return role;
            }
            //添加资源
            @PostMapping
            public Integer add(Role role){
                if(role.getName() != null){
                   return 0;
                }
                return 1;
            }
            //更新资源
            @PutMapping
            public String update(Role role){
                role.setSn("123");
                return role.getSn();
        
            }
            //删除资源
            @DeleteMapping
            public Long delete(Long id){
                return id;
        
            }
        }
        
  • 相关阅读:
    贪心算法
    分治法
    递归法
    查找二 树与图的搜索
    (转载)查找三 哈希表的查找
    (转载)查找一 线性表的查找
    4.写出完整版的strcpy函数
    3.strcpy使用注意(3)
    2.strcpy使用注意(2)
    1.strcpy使用注意
  • 原文地址:https://www.cnblogs.com/dai-tao/p/13125350.html
Copyright © 2011-2022 走看看