Swagger UI 使用实例
2016-07-22 18:20
716 查看
类上依赖jar包pom.xml:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-staticdocs</artifactId>
<version>2.4.0</version>
</dependency>
spring的配置文件中加入:
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/" />
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/" />
类上所加注释:
方法上所加注释:
页面效果如下
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-staticdocs</artifactId>
<version>2.4.0</version>
</dependency>
spring的配置文件中加入:
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/" />
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/" />
类上所加注释:
@Api(value = "有效期规则定义-api", description = "有效期规则定义API") @Controller @RequestMapping(value="/validitRuleDefine") public class ValiditRuleDefController {</span>
方法上所加注释:
private static final String INSERTVALIDITRULE ="{\"startDate\":\"2016-07-20\",\"endDate\":\"2016-07-21\",\"expireTime\":\"2016-07-21\"}"; /** * 添加有效期规则定义 * @param request * @return */ @ApiOperation(value = "新增有效规则定义", notes = "新增有效规则定义") @ApiResponses(value = { @ApiResponse(code = 200, message = "返回结果 -- state:0(成功),state:非0(失败)") }) @RequestMapping(value="/insert",method=RequestMethod.POST) @ResponseBody public Map<String,Object> insertRule(HttpServletRequest request, @ApiParam(value = INSERTVALIDITRULE)@RequestParam String json){ int resultCode=Constant.CODE_SUCCESS0; String resultName="保存成功"; Map<String,Object> mapData=new HashMap<String,Object>(); ExpirySet expirySet = new ExpirySet(); try { expirySet = (ExpirySet) JsonUtil.jsonToObjectYYMMDD(json, ExpirySet.class); expirySet.setStatus(0); } catch (Exception e) { e.printStackTrace(); logger.error("ValiditRuleDefController.save error", e); return JsonUtil.returnData(Constant.CODE_CLIENT_ERROR, "客户端数据异常", mapData); }。。。。。。
页面效果如下
相关文章推荐
- html5 web数据存储
- SEO
- 异步流程控制:7 行代码学会 co 模块
- [译] React 入门
- 如何优雅处理前端异常?
- 前端jquery部分很精彩
- 深入探讨前端框架react
- Express实现前端后端通信上传图片之存储数据库(mysql)傻瓜式教程(一)
- 自己动手写的javascript前端等待控件
- 前端必备神器 Snap.svg 弹动效果
- 一张Web前端的思维导图分享
- 带有定位当前位置的百度地图前端web api实例代码
- 一道常被人轻视的web前端常见面试题(JS)
- 浅谈AngularJS--基础
- 浅谈AngularJS--域变量(scope)
- AngularJS' Internals In Depth(深入理解 AngularJS)
- 3ff8 javascript 获取Flash下载进度兼容IE, FireFox,Chrome浏览器
- CSS清除浮动常用方法小结