接博客--->Idea创建spring boot 项目(1)
使用工具:
IDE:idea 2017.2.6
spring boot 版本:1.5.9
构建工具:gradle
Swagger版本:Swagger 2.7.0
1、项目工程原结构如下:三处红框需要修改的
2、修改后如下图:
(1)修改了包名com.demo.demo--->com.demo;
(2)修改了启动类名DemoApplicatioin--->App;
(3)删除了test及其以下的包;
ps:个人习惯
3、Swagger简述:
Swagger 是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。总体目标是使客户端和文件系统作为服务器以同样的速度来更新。文件的方法,参数和模型紧密集成到服务器端的代码,允许API来始终保持同步。Swagger 让部署管理和使用功能强大的API从未如此简单。
Swagger通过注解表明该接口会生成文档,包括接口名、请求方法、参数、返回信息的等等。
@Api:修饰整个类,描述Controller的作用
@ApiOperation:描述一个类的一个方法,或者说一个接口
@ApiParam:单个参数描述
@ApiModel:用对象来接收参数
@ApiProperty:用对象接收参数时,描述对象的一个字段
@ApiResponse:HTTP响应其中1个描述
@ApiResponses:HTTP响应整体描述
@ApiIgnore:使用该注解忽略这个API
@ApiError :发生错误返回的信息
@ApiParamImplicitL:一个请求参数
@ApiParamsImplicit 多个请求参数
4、修改后的项目的build.gradle文件:
(注意引用的中央仓库仓库是阿里云的仓库,Swagger的版本是2.7.0)
buildscript { ext { springBootVersion = '1.5.9.RELEASE'//spring boot 版本 } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } //添加资源库 repositories { maven { url 'http://maven.aliyun.com/nexus/content/repositories/central' }//添加阿里仓库 mavenCentral()//添加Maven中央资源库 } apply plugin: 'java'// 指定项目为java项目,项目编译(在项目提示符下执行:gradle build)时生成项目的jar包。 apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'spring-boot' apply plugin: 'application' group = 'com.demo' version = '1.5.9-SNAPSHOT' sourceCompatibility = 1.8 targetCompatibility = 1.8 mainClassName = 'com.tinckay.App'//告诉gradle启动类的路径 dependencies { compile("org.springframework.boot:spring-boot-starter-web") testCompile("org.springframework.boot:spring-boot-starter-test") compile("org.springframework.boot:spring-boot-starter-tomcat") compile("io.springfox:springfox-swagger2:2.7.0")//swagger2核心依赖 compile("io.springfox:springfox-swagger-ui:2.7.0")//为项目提供api