-
引入依赖
<dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>knife4j-spring-boot-starter</artifactId> <version>3.0.3</version> </dependency> -
添加配置
@EnableSwagger2 @EnableKnife4j @Configuration public class SwaggerConfig { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("cn.ccb.controller")) .paths(PathSelectors.any()) .build().globalOperationParameters(pars); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title(title) .description(description) .version(version) .build(); } } -
编写controller
@ApiOperation(value = "获取用户信息", produces = "application/json") @RequestMapping(value = "/base/getInfo", method = RequestMethod.GET) public Result getAllInfo () { userService.getAllInfo(); return Result.success("ok"); }