1、用idea创建spring boot 项目
2、由于我用的的是maven做包管理,所以首先在pom文件中添加依赖
3、在spring boot 中的启动类的同级录中创建一个配置类
代码如下:
@Configuration
@EnableSwagger2
public class Swagger2 {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.demo"))
.paths(PathSelectors.regex("/demo/.*"))
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("个人日记系统 API")
.description("个人日记系统 API")
.termsOfServiceUrl("http://127.0.0.1:8080/")
.contact("guojianlu")
.version("1.0")
.build();
}
}
4、直接运行程序就然后在浏览器上输入上面配置的地址http://127.0.0.1:8080/就能看到效果 了;
閱讀更多 匠心一笑 的文章
關鍵字: 技术