欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

eclipse内置swagger。maven项目spring boot框架

程序员文章站 2022-03-19 14:59:34
...

1.添加依赖

<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>

        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>swagger-bootstrap-ui</artifactId>
            <version>1.9.6</version>
        </dependency>

2.添加swagger配置

import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
@Configuration
@EnableSwagger2
public class swaggerConfig {
	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2)
				.groupName("controller")
				.apiInfo(apiInfo())
				.select()
				.apis(RequestHandlerSelectors.basePackage("com.pusamm"))//项目包名
				.paths(PathSelectors.any()).build();
	}
 
 
	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("移动C2M RESTful API")
				.description("swagger-ui")
				.termsOfServiceUrl("").version("1.0").build();
}

3.细节配置
eclipse内置swagger。maven项目spring boot框架

@Slf4j
@Api(value = "Api Documentation")
@RestController
@RequestMapping("api/test")
public class ApisController {
    private final CabinetInformationService cabinetInformationService;
    

   public ApisController(final CabinetInformationService cabinetInformationService) {
	   this.cabinetInformationService = cabinetInformationService;
    }
	  
      @ApiAbility(permission = true)
	  @ApiOperation(value = "1.柜子信息查询接口", notes = "根据业务方id查询柜子的信息")
	  @PostMapping("/cabinet/query")
	  public List<CabinetQueryBack> cabinetInformationQuery(CabinetQuery req) {
		  List<CabinetQueryBack> list = null;
	      try {
	    	  list = cabinetInformationService.query(req);
	      }catch (Exception e) {
	    	  logger.error("柜子信息查询接口出错:{}", e.getMessage(), e);
	      }
	      return list;	  
	  }

4 启动项目 访问 http://localhost:8080/swagger-ui.html
eclipse内置swagger。maven项目spring boot框架

相关标签: 个人