We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.7.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.7.0</version> </dependency>
@Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .pathMapping("/")// base,最终调用接口后会和paths拼接在一起 .select() .paths(or(regex("/api/.*")))//过滤的接口 .build() .apiInfo(testApiInfo()); } private ApiInfo testApiInfo() { return new ApiInfoBuilder() .title("大标题大标题大标题")//大标题 .description("详细描述详细描述")//详细描述 .version("1.0版本版本")//版本 .termsOfServiceUrl("NO terms of service") .contact("/作者/作者/作者 ")//作者 .license("The Apache License, Version 2.0") .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") .build(); } }
@RestController public class SwaggerController { @ApiOperation(value = "获取用户详细信息", notes = "根据url的id来获取用户详细信息") @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long") @RequestMapping(value = "/api/{id}", method = RequestMethod.GET) public Error400 getUser(@PathVariable Long id) { Error400 er = new Error400(); return er; } @ApiOperation(value = "创建用户", notes = "根据User对象创建用户") @ApiResponses({ @ApiResponse(code = 400, message = "请求参数没填好"), @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对", response = Error400.class) }) @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User") @RequestMapping(value = "/api/user", method = RequestMethod.POST) public String postUser(@RequestBody User user) { return "success"; } }
@ApiModel(value = "400Error") public class Error400 { /** * 错误反馈编码 */ @ApiModelProperty(value = "错误反馈编码") private String respCode; /** * 错误反馈描述 */ @ApiModelProperty(value = "错误反馈描述") private String respDesc; //省略get set }
The text was updated successfully, but these errors were encountered:
启动项目,访问http://localhost:8080/swagger-ui.html
Sorry, something went wrong.
No branches or pull requests
The text was updated successfully, but these errors were encountered: