1、安装Swagger插件
访问地址:
http://localhost:8080/fsoa.usermanager.web/swagger-ui.html#/
2、Controller层(参考)
package com.foriseland.open.controll;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
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 com.foriseland.fjf.rpc.storage.Request;
import com.foriseland.fjf.rpc.storage.Response;
import com.foriseland.fsoa.open.consumer.api.IProductApi;
import com.foriseland.fsoa.open.consumer.dto.ProductDto;
import com.foriseland.fsoa.open.consumer.vo.ProductVo;
import io.swagger.annotations.Api;
@Controller
@CrossOrigin
@Api(tags="商品信息")
@RestController
@RequestMapping(value = "/product")
public class ProductController extends BaseController {
private Logger logger = LoggerFactory.getLogger(ProductController.class);
@Autowired
private IProductApi productApi;
/**
* @describe 商品批量插入
* @returnType void
* @createTime 2018年3月29日 下午5:20:50
*/
@RequestMapping(value="/saveBatch",method = RequestMethod.POST)
public void saveBatch(@RequestBody List<ProductDto> transferList, HttpServletResponse response) {
Request<List<ProductDto>> req = Request.create();
Response<ProductVo> res = Response.create();
if(transferList.size()>0) {
req.setData(transferList);
res = productApi.saveBatch(req);
}else {
res.setSuccess(false);
res.setErrorMsg("操作失败!请求参数不能为空");
}
if (res.getData() != null) {
res.setSuccess(true);
}else {
res.setErrorMsg("商品信息批量插入失败!");
}
writeJson(res, transferList, response);
}
/**
* @describe 商品信息列表
* @returnType void
* @createTime 2018年3月29日 下午5:20:41
*/
@RequestMapping(value="/searchProductList",method = RequestMethod.POST)
public void searchProductList(@RequestBody ProductDto transfer, HttpServletResponse response) {
Request<ProductDto> req = Request.create();
Response<List<ProductVo>> res = Response.create();
if(transfer != null) {
req.setData(transfer);
res = productApi.searchProductList(req);
}else {
res.setSuccess(false);
res.setErrorMsg("操作失败!请求参数不能为空");
}
if (res.getData() != null) {
res.setSuccess(true);
}else {
res.setErrorMsg("查询商品信息失败!");
}
writeJson(res, transfer, response);
}
}