zoukankan      html  css  js  c++  java
  • 给EmpMapper开放Restful接口

    本文例程下载:https://files.cnblogs.com/files/xiandedanteng/gatling20200428-3.zip

    接口控制器代码如下:

    请求url和响应都写在了每个接口的注释上。

    package com.ufo.gatling.ctrl;
    
    import java.util.List;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    import com.ufo.gatling.entity.Emp;
    import com.ufo.gatling.mapper.EmpMapper;
    
    @RestController
    @RequestMapping("/emp")
    public class EmpCtrl {
        @Autowired
        private EmpMapper empMapper=null;
        
        // http://localhost:8080/emp/test
        // Hello Gatling
        @RequestMapping("/test")
        String test() {
            return "Hello Gatling";
        }
        
        // http://localhost:8080/emp/
        // [{"id":1,"name":"Andy","salary":10000},{"id":2,"name":"Bill","salary":12000},{"id":3,"name":"Cindy","salary":16000},{"id":4,"name":"Douglas","salary":17500},{"id":5,"name":"Eliot","salary":18000},{"id":6,"name":"Felix","salary":20000}]
        @RequestMapping("/")
        List<Emp> findAll() {
            return empMapper.findAll();
        }
        
        // http://localhost:8080/emp/findbyid/5
        // {"id":5,"name":"Eliot","salary":18000}
        @RequestMapping("/findbyid/{id}")
        Emp findById(@PathVariable("id") long id) {
            return empMapper.findById(id);
        }
        
        // http://localhost:8080/emp/updateById/1/gatesss/12345
        // ok
        @RequestMapping("/updateById/{id}/{name}/{salary}")
        String updateById(@PathVariable("id") long id,
                      @PathVariable("name") String name,
                      @PathVariable("salary") int salary) {
            
            Emp emp=new Emp();
            emp.setId(id);
            emp.setName(name);
            emp.setSalary(salary);
            
            int changedCount=empMapper.updateById(emp);
            
            return changedCount==1?"ok":"ng";
        }
        
        // http://localhost:8080/emp/deleteById/1
        // ok
        @RequestMapping("/deleteById/{id}")
        String deleteById(@PathVariable("id") long id) {
            Emp emp=new Emp();
            emp.setId(id);
            int changedCount=empMapper.deleteById(emp);
            return changedCount==1?"ok":"ng";
        }
        
        // http://localhost:8080/emp/insert/1/ufo/99999
        // ok
        @RequestMapping("/insert/{id}/{name}/{salary}")
        String insert(@PathVariable("id") long id,
                      @PathVariable("name") String name,
                      @PathVariable("salary") int salary) {
            
            Emp emp=new Emp();
            emp.setId(id);
            emp.setName(name);
            emp.setSalary(salary);
            
            int changedCount=empMapper.insert(emp);
            
            return changedCount==1?"ok":"ng";
        }
        
        // http://localhost:8080/emp/findHighLevelEmps
        // [{"id":3,"name":"Cindy","salary":16000},{"id":4,"name":"Douglas","salary":17500},{"id":5,"name":"Eliot","salary":18000},{"id":6,"name":"Felix","salary":20000},{"id":1,"name":"ufo","salary":99999}]
        @RequestMapping("/findHighLevelEmps")
        List<Emp> findHighLevelEmps() {
            return empMapper.findHighLevelEmps();
        }
    }

    --2020-04-28--

  • 相关阅读:
    BindingException: Parameter 'approval_state' not found. Available parameters are [arg1, arg0, param1, param2]]
    vue.js学习笔记(一)——vue-cli项目的目录结构
    memcpy函数
    与、或、异或运算
    C++中的dynamic_cast和dynamic_pointer_cast
    django中orm之什么是正向查询什么是反向查询
    jquery笔记
    jquery
    前端操作数组
    Auto Layout Guide----(三)-----Anatomy of a Constraint
  • 原文地址:https://www.cnblogs.com/heyang78/p/12795898.html
Copyright © 2011-2022 走看看