摘要:版本开启注解配置启动后访问参考之使用展示的
swagger版本
com.mangofactory
</>复制代码
com.mangofactory
swagger-springmvc
1.0.2
io.springfox
</>复制代码
2.2.2
io.springfox
springfox-swagger-ui
${springfox.version}
io.springfox
springfox-swagger2
${springfox.version}
开启swagger2
</>复制代码
/**
* Created by codecraft on 2016-05-05.
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket swaggerSpringMvcPlugin() {
return new Docket(DocumentationType.SWAGGER_2)
.select().paths(paths()).build().apiInfo(apiInfo());
}
@SuppressWarnings("unchecked")
private Predicate paths() {
return Predicates.or(Predicates.containsPattern("/api/*"));
}
private ApiInfo apiInfo() {
String title = "my api";
String description = "api desc";
String version = "1.0.0-snapshot";
String contact = "codecraft@gmail.com";
ApiInfo apiInfo = new ApiInfo(title,description,version,
"terms of service", contact, "", "");
return apiInfo;
}
}
domain注解
</>复制代码
package com.codecraft.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
* Created by codecraft on 2016-05-05.
*/
@ApiModel
public class User {
@ApiModelProperty(value = "User ID")
private String id;
@ApiModelProperty(value = "first name")
private String firstName;
@ApiModelProperty(value = "last name")
private String lastName;
public User() {
}
public User(String id, String firstName, String lastName) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
}
controller配置
</>复制代码
@RestController
@RequestMapping("/api/user")
public class UserController {
private ConcurrentHashMap userMap = new ConcurrentHashMap<>();
@RequestMapping(method = RequestMethod.POST)
public String add(@RequestBody
@ApiParam(name = "user",value = "json format",required = true)
User user){
userMap.put(user.getId(),user);
return "add successfully";
}
@RequestMapping(method = RequestMethod.PUT)
public String update(@RequestBody
@ApiParam(name = "user",value = "json format",required = true)
User user) {
userMap.put(user.getId(),user);
return "update successfully";
}
@RequestMapping(method = RequestMethod.GET)
public User get(@RequestParam(value = "id", required = true) String id){
return userMap.get(id);
}
@RequestMapping(method = RequestMethod.DELETE)
public String delete(@RequestParam(value = "id", required = true) String id){
userMap.remove(id);
return "delete successfully";
}
}
启动后访问
http://localhost:8080/swagger-ui.html
spring boot之使用springfox swagger展示restful的api doc
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/65876.html
摘要:今天给你们带来集成的教程。接口返回结果不明确。这些痛点在前后端分离的大型项目上显得尤为烦躁。接口返回结果非常明确,包括数据类型,状态码,错误信息等。生成后的文件依赖如下这里使用的是的版本。另外,关注之后在发送可领取免费学习资料。 微信公众号:一个优秀的废人如有问题或建议,请后台留言,我会尽力解决你的问题。 前言 快过年了,不知道你们啥时候放年假,忙不忙。反正我是挺闲的,所以有时间写 b...
摘要:前后端分离后,维护接口文档基本上是必不可少的工作。一个理想的状态是设计好后,接口文档发给前端和后端,大伙按照既定的规则各自开发,开发好了对接上了就可以上线了。本文主要和大伙来聊下在中如何整合。如此,就算配置成功了,非常方便。 前后端分离后,维护接口文档基本上是必不可少的工作。一个理想的状态是设计好后,接口文档发给前端和后端,大伙按照既定的规则各自开发,开发好了对接上了就可以上线了。当然...
摘要:新手上路搭建项目是一个接口文档软件界面如下添加这里使用版本可以正常使用配置文件测试新手上路。 新手上路-搭建项目-springboot-swagger2 swagger2 是一个接口文档软件 界面如下 showImg(https://segmentfault.com/img/bVOoim); gradle添加 compile(io.springfox:springfox-swagger...
阅读 4381·2021-09-26 10:17
阅读 958·2021-09-22 15:02
阅读 3588·2021-09-06 15:00
阅读 1141·2021-07-25 16:52
阅读 2842·2019-08-29 16:16
阅读 2600·2019-08-29 13:25
阅读 1657·2019-08-26 13:51
阅读 2258·2019-08-26 10:58