internship:接口案例实现

继上一次的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;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值