java自动生成接口文档_Spring集成Swagger,Java自动生成Api文档

swagger最终效果图

9844292d292c346f5b4e3c6246f7542e.png

好,开始说Spring怎么配置Swagger了

1.pom.xml引入需要的jar包

io.springfox

springfox-swagger2

${swagger2.version}

io.springfox

springfox-swagger-ui

${swagger2.version}

2.扫描你的Swagger2config.java所在的包

3.Swagger2config.java[类名自定义]

package com.nickwilde.microtrain.common.config.swagger2;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;

import springfox.documentation.builders.PathSelectors;

import springfox.documentation.builders.RequestHandlerSelectors;

import springfox.documentation.service.ApiInfo;

import springfox.documentation.service.Contact;

import springfox.documentation.spi.DocumentationType;

import springfox.documentation.spring.web.plugins.Docket;

import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**

* @author NickWilde

* @version 2018/1/18 10:23

* @description: Swagger2Config

* TODO 用一句话描述

*/

@Configuration

@EnableSwagger2

public class Swagger2Config{

@Bean

public Docket api() {

return new Docket(DocumentationType.SWAGGER_2).forCodeGeneration(true)

.select()

.apis(RequestHandlerSelectors.any())

//过滤生成链接

.paths(PathSelectors.any())

.build()

.apiInfo(apiInfo());

}

//api接口作者相关信息

private ApiInfo apiInfo() {

Contact contact = new Contact("NickWilde", "", "1064698801@qq.com");

ApiInfo apiInfo = new ApiInfoBuilder()

.license("Apache License Version 2.0")

.title("Unexpectedly系统")

.description("接口文档")

.contact(contact)

.version("1.0")

.build();

return apiInfo;

}

}

4.给你的controller加上额外注解(不加也是有的)

@ApiOperation(value="根据User对象创建用户", notes="根据User对象创建用户",httpMethod = "POST") //httpMehtod如果不定义,那么swagger会有把该接口的所有请求方法都一一列举出来

@ApiImplicitParam(name = "data", value = "data描述", required = true, dataType = "UserInfo") //参数定义..类型..之类的,这是基础简单,其余的看api吧~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值