一、准备工作
1、准备一个持续集成的代码工程
工程下载地址:
Github地址为:https://github.com/zbbkeepgoing/springboot-demo
2、springboot-demo代码工程介绍
整个Web工程有一个Index页面,上面有两个按钮,分别对应两个接口,其中一个接口直接返回信息,另外一个接口则是内存中请求一次延时1s,最大延时为10s。而对应Index会有一个接口,所以Web工程一共有3个接口。延时接口主要是为了后续性能测试
①工程结构
└── src
├── main
│ ├── java
│ │ └── com
│ │ └── dxc
│ │ └── ddccloud
│ │ └── demo
│ │ ├── controller
│ │ │ └── DemoController.java #控制器,接口定义类
│ │ └── DemoApplication.java #启动类
│ └── resources
│ ├── application.properties #配置文件
│ └── templates
│ └── index.html #首页Index
└── test
└── java
└── com
└── dxc
└── ddccloud
└── demo
└── DemoControllerTests.java #单元测试类
②DemoController.java
package com.dxc.ddccloud.demo.controller; import java.util.Map; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.ModelAndView; @RestController public class DemoController { public int tmp = 0; @RequestMapping("/") #首页接口 public ModelAndView index(ModelAndView mv) { mv.setViewName("index"); mv.addObject("requestname","This request is IndexApi"); return mv; } @RequestMapping("/rightaway") #立即返回接口 public ModelAndView returnRightAway(ModelAndView mv) { mv.setViewName("index"); mv.addObject("requestname","This request is RightawayApi"); return mv; } @RequestMapping("/sleep") #延时接口 public ModelAndView returnSleep(ModelAndView mv) throws InterruptedException { Thread.sleep(tmp*1000); if(tmp < 10) { tmp++; } mv.setViewName("index"); mv.addObject("requestname","This request is SleepApi"+",it will sleep "+ tmp +"s !"); return mv; } }