Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions back/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@
<version>1.18.20</version>
<scope>provided</scope>
</dependency>

<!-- swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>

</dependencies>
<build>
<plugins>
Expand Down
2 changes: 2 additions & 0 deletions back/src/main/java/com/heeexy/example/MyApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
* @author: heeexy
* @description: SpringBoot启动类
* @date: 2017/10/24 11:55
*/
@EnableSwagger2
@SpringBootApplication
@MapperScan("com.heeexy.example.dao")
public class MyApplication extends SpringBootServletInitializer {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.heeexy.example.config.swagger;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration // 标明是配置类
@EnableSwagger2 //开启swagger功能
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2) // DocumentationType.SWAGGER_2 固定的,代表swagger2
//.groupName("分布式任务系统") // 如果配置多个文档的时候,那么需要配置groupName来分组标识
.apiInfo(apiInfo()) // 用于生成API信息
.select() // select()函数返回一个ApiSelectorBuilder实例,用来控制接口被swagger做成文档
// 扫描指定包下的接口,最为常用
.apis(RequestHandlerSelectors.basePackage("com.heeexy.example"))
//.withClassAnnotation(RestController.class) // 扫描带有指定注解的类下所有接口
//.withMethodAnnotation(PostMapping.class) // 扫描带有指定注解的方法接口
//.apis(RequestHandlerSelectors.any()) // 扫描所有

// 选择所有的API,如果你想只为部分API生成文档,可以配置这里
.paths(PathSelectors.any()
//.any() // 满足条件的路径,该断言总为true
//.none() // 不满足条件的路径,该断言总为false(可用于生成环境屏蔽 swagger)
//.ant("/user/**") // 满足字符串表达式路径
//.regex("") // 符合正则的路径
)
.build();
}

/**
* 用于定义API主界面的信息,比如可以声明所有的API的总标题、描述、版本
* @return
*/
private ApiInfo apiInfo() {

Contact contact = new Contact(
"我是作者刘朝阳", // 作者姓名
"https://blog.csdn.net/", // 作者网址
"123456789@163.com"); // 作者邮箱

return new ApiInfoBuilder()
.title("springboot-shiro-vue项目API") // 可以用来自定义API的主标题
.description("项目SwaggerAPI管理") // 可以用来描述整体的API
.termsOfServiceUrl("https://www.baidu.com") // 用于定义服务的域名(跳转链接)
.version("1.0") // 可以用来定义版本
.license("Swagger-的使用教程")
.licenseUrl("https://blog.csdn.net")
.contact(contact)
.build(); //
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.heeexy.example.config.annotation.RequiresPermissions;
import com.heeexy.example.service.ArticleService;
import com.heeexy.example.util.CommonUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

Expand All @@ -16,6 +17,7 @@
*/
@RestController
@RequestMapping("/article")
@Api(value = "用户接口", tags = {"用户接口"})
public class ArticleController {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSONObject;
import com.heeexy.example.service.LoginService;
import com.heeexy.example.util.CommonUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -16,6 +17,7 @@
*/
@RestController
@RequestMapping("/login")
@Api(value = "登录接口", tags = {"登录接口"})
public class LoginController {

@Autowired
Expand Down
1 change: 1 addition & 0 deletions back/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
spring:
profiles:
active: local

mybatis:
mapperLocations: classpath:/mapper/*.xml