您的位置:首页 > 产品设计 > UI/UE

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/" />
类上所加注释:

@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);
}。。。。。。


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