本文例程下载: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--

给EmpMapper开放Restful接口的更多相关文章

  1. Swagger: 一个restful接口文档在线生成+功能测试软件

    一.什么是 Swagger? Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件.Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 ...

  2. 开放数据接口 API 简介与使用场景、调用方法

    此文章对开放数据接口 API 进行了功能介绍.使用场景介绍以及调用方法的说明,供用户在使用数据接口时参考之用. 在给大家分享的一系列软件开发视频课程中,以及在我们的社区微信群聊天中,都积极地鼓励大家开 ...

  3. RESTful接口签名认证实现机制

    RESTful接口 互联网发展至今,催生出了很多丰富多彩的应用,极大地调动了人们对这些应用的使用热情.但同时也为互联网应用带来了严峻的考验.具体体现在以下几个方面: 1.     部署方式的改变:当用 ...

  4. RESTful 接口调试分享利器 restc

    这个工具来自于https://elemefe.github.io/restc/  这里对Abp进行了一次封装 1.在项目中添加nuget包 Abp.Web.Api.Restc 2.在项目Abp模块的D ...

  5. RESTful接口设计原则/最佳实践(学习笔记)

    RESTful接口设计原则/最佳实践(学习笔记) 原文地址:http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api 1 ...

  6. Apple Watch已向微信开放WatchKit接口?

    Apple Watch在北京时间凌晨1点的苹果发布会上首次对外公布了,一时间applewatch占据了各大媒体.早上也早早地看了相关新闻,其中福布斯中文网的一则消息分外引起@隔壁W叔叔的注意,“苹果同 ...

  7. Swagger+Spring mvc生成Restful接口文档

    简介 Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目标是使客户端和文件系统作为服务器以同样的速度来更新.文件的方法,参数和模型紧密集 ...

  8. [转]简单识别 RESTful 接口

         本文描述了识别一个接口是否真的是 RESTful 接口的基本方法.符合 REST 架构风格的接口,称为 RESTful 接口.本文不打算从架构风格的推导方面描述,而是从 HTTP 标准的方面 ...

  9. 运用百度开放平台接口根据ip地址获取位置

    使用百度开放平台接口根据ip地址获取位置 今天无意间发现在百度开放平台接口,就把一段代码拿了下来,有需要的可以试试看:http://opendata.baidu.com/api.php?query=5 ...

随机推荐

  1. 20、FlyWeight 享元模式

    池化的思想 1.Flyweight享元模式 运用共享技术有效地支持大量细粒度对象的复用.系统只使用少量的对象,而这些对象都很相似,状态变化很小,可以实现对象的多次复用.由于享元模式要求能够共享的对象必 ...

  2. SQL Server2017+SSIS+Python

    1.安装SQL Server2017 https://jingyan.baidu.com/article/76a7e409077997fc3a6e1559.html (1)JRE 7报错 只能安装JR ...

  3. 【JavaScript】windows.open用法详解

    windows.open("URL","窗口名称","窗口外观设定");的用法详解 function onNewWindows(redire ...

  4. C#开发笔记之01-为什么开源框架会大量的使用protected virtual?

    C#开发笔记概述 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/957 访问. 我们在很多开源框架中会经常看到prote ...

  5. externaltrafficpolicy的有关问题说明

    环境描述 生产环境通过gitlab-running实现自动化发布业务,现需要收集客户端的真实ip,需要将externaltrafficpolicy改为lacal模式(原来是cluster模式),前天开 ...

  6. 炼技术(9): 简约而不简单,永不停歇的测试 -- always_run

    最强战力,永不停歇的测试:always_run 许多工程师写完程序后,都不愿意对自己的程序做仔细测试. 很多测试说会做自动化测试,可能工作好几年都没真做过多少自动化测试. 我们的解决方案是,在系统的测 ...

  7. 【算法•日更•第二期】查找算法:三分VS二分

    ▎前言:函数 如果你已经上过初二的数学课了,那么你十有八九会被函数折磨到吐血,这是一种中考压轴题类的题目,往往分类讨论到你恶心.不过没学过也不打紧,现场讲解一下: ☞『数学中的函数』 一般地,如果在一 ...

  8. 由Thread.join引发的思考

    下面是一段司空见惯的代码,创建两个线程A和线程B,使得线程A优先于线程B执行,使得线程B优先于主线程执行 public class Demo52 { public static void main(S ...

  9. bluetoothctl命令提示No default controller available

    在学习bluetoothctl命令时,执行bluetoothctl,然后执行show,提示No default controller available. 1. 执行hciconfig,发现有hci0 ...

  10. three.js 制作逻辑转体游戏(下)

    上一篇已经对绕非定轴转动有所了解,这篇郭先生继续说一说逻辑转体游戏的制作,这部分我们同样会遇到一些小问题,首先是根据数据渲染陷阱和目标区域,然后是对可以转动的判定,最后是获胜的判定. 1. 根据数据渲 ...