您的位置:首页 > 编程语言 > Java开发

spring Swagger生成API文档

2018-01-12 14:29 471 查看
package com.xyh.controller;
import java.net.URL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.netflix.discovery.DiscoveryClient;
import com.netflix.governator.annotations.binding.Request;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;

@RestController
@EnableDiscoveryClient
@Api(value="city",description="城市管理")
@RequestMapping(value="/city")
public class cityController {

@Autowired
private RestTemplate restTemplate;

@Value("${eureka.client.service-url.defaultZone}")
private String  datasourceUrl;

@ApiOperation(value="获取城市列表",notes="/findbycityPage")
@RequestMapping(value="/findbycityPage",method= RequestMethod.POST)
public JSONObject  findbycityPage(@RequestBody JSONObject json)
{
JSONObject res= new JSONObject();
res =  this.restTemplate.postForObject(datasourceUrl+"/data/findcity",json,JSONObject.class);
return res;
}

@ApiOperation(value="保存城市信息",notes="/saveCity")
@RequestMapping(value= "/saveCity",method= RequestMethod.POST)
public JSONObject saveCity(@RequestBody JSONObject json)
{
JSONObject res= new JSONObject();
res= this.restTemplate.postForObject(datasourceUrl+"/data/saveCity", json, JSONObject.class);
return res;
}

@ApiOperation(value="修改城市信息",notes="/updateCity")
@RequestMapping(value= "/updateCity",method= RequestMethod.POST)
public JSONObject updateCity(@RequestBody JSONObject json)
{
JSONObject res= new JSONObject();
res= this.restTemplate.postForObject(datasourceUrl+"/data/updateCity", json, JSONObject.class);
return res;
}
@ApiOperation(value="删除城市信息",notes="/deleteCity")
@RequestMapping(value= "/deleteCity",method= RequestMethod.POST)
public JSONObject deleteCity(@RequestBody JSONObject json)
{
JSONObject res= new JSONObject();
res= this.restTemplate.postForObject(datasourceUrl+"/data/deleteCity", json, JSONObject.class);
return res;
}
@ApiOperation(value="根据id查找城市信息",notes="/findcityById")
@RequestMapping(value= "/findcityById",method= RequestMethod.POST)
public JSONObject findcityById(@RequestBody JSONObject json)
{
JSONObject res= new JSONObject();
res= this.restTemplate.postForObject(datasourceUrl+"/data/findcityById", json, JSONObject.class);
return res;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: