小程序后台
1.后台结构:
如图1所示为传统的单项目工程,将所有层都写在一个工程中,项目较大不利用后期修改,适用于小型项目。

本小程序后台采用maven搭建分成的聚合工程,如图2所示,子工程是作为module存在的。

图3是视频后台搭建的模块图

2.Swagger2的使用
swagger介绍,可以帮助我们更好地管理接口,接口以网站形式进行展示,方便前端人员查看,有利于接口对接,简化开发。
使用swagger2构建restful接口测试步骤:
1.在common工程下引入依赖
<!-- swagger2 配置 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
2.在application同级文件下配置Swagger2.java文件
@Configuration
@EnableSwagger2
public class Swagger2 {
/**
* @Description:swagger2的配置文件,这里可以配置swagger2的一些基本的内容,比如扫描的包等等
*/
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
.apis(RequestHandlerSelectors.basePackage("com.jxw.controller"))
.paths(PathSelectors.any()).build();
}
/**
* @Description: 构建 api文档的信息
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
// 设置页面标题
.title("使用swagger2构建短视频后端api接口文档")
// 设置联系人
.contact(new Contact(&#