继上一次的demo完成之后 给了两份数据,两者都是json格式。要求编写两个接口 返回json格式数据。
实质:两个接口可同写于一个类下,运行输入url输出json格式数据。
package com.hyd.daring.api;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hyd.daring.common.response.ResponseData;
import com.hyd.daring.model.module.ModuleScheduleInfo;
import com.hyd.daring.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
*
* demo 接口案例
*
* @author yyp
*/
@RequestMapping("/Demo")
@RestController
@Api(tags = "demo 1/2")
@Validated
@Slf4j
public class Demo {
@Resource
private IBizTunnelService iBizTunnelService;
@RequestMapping(value = "/arg",method = RequestMethod.GET)
@ApiOperation(value = "获取各个参数设置")
@ApiOperationSupport(order = 1)
public ResponseData<List<ModuleScheduleInfo>> moduleScheduleInfo ()
{
return new ResponseData<>(iBizTunnelService.moduleScheduleInfo());
}
@RequestMapping(value = "/arg1",method = RequestMethod.GET)
@ApiOperation(value = "详细坐标参数")
@ApiOperationSupport(order=2)
public ResponseData<List<Map>> listResponseData()
{
return new ResponseData<>(iBizTunnelService.arg2());
}
}
public List<Map> arg2() {
List<Map> list=new ArrayList<>();
String[] str=new String[5];
str[0]="ybgg";
str[1]="zfxjj";
str[2]="gyzcjy";
str[3]="shbzjj";
str[4]="total";
Double[] doubles=new Double[5];
doubles[0]=137631.17;
doubles[1]=1404.3;
doubles[2]=0.29;
doubles[3]=0.0;
doubles[4]=139035.76;
Map<String,Object[]> map=new HashMap<>();
Map<String,Double>[] maps=new Map[3];
for (int i = 0; i < 3; i++) {
maps[i]=new HashMap<>();
}
for (int i = 0; i < 3; i++) {
if(i==0)
{
for (int j = 0; j <5; j++) {
maps[i].put(str[j],doubles[j]);
}
}
else
{
for (int k = 0; k <5; k++) {
maps[i].put(str[k],0.0);
}
}
}
Integer[] integers=new Integer[3];
integers[0]=2022;
integers[1]=2021;
integers[2]=2020;
map.put("xaxis",integers);
map.put("yaxis1",maps);
map.put("yaxis2",maps);
list.add(map);
return list;
}
}