
怎么把swagger加入到项目中12和3/** * 配置类注册web层相关组件 */ Configuration Slf4j public class WebMvcConfiguration extends WebMvcConfigurationSupport { /** * 通过knife4j生成接口文档 * return */ Bean public Docket docket() { ApiInfo apiInfo new ApiInfoBuilder() .title(苍穹外卖项目接口文档) .version(2.0) .description(苍穹外卖项目接口文档) .build(); Docket docket new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo) .select() .apis(RequestHandlerSelectors.basePackage(com.sky.controller)) .paths(PathSelectors.any()) .build(); return docket; } /** * 设置静态资源映射 * param registry */ Override protected void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler(/doc.html).addResourceLocations(classpath:/META-INF/resources/); registry.addResourceHandler(/webjars/**).addResourceLocations(classpath:/META-INF/resources/webjars/); } }请求到localhost:8080/doc.html即可看到swagger页面常用注解Api(tags xxxxx)ApiModel(description xxxxxx)ApiModelProperty(xxxxxx)ApiOperation(xxxxxx)