增加swagger-bootstrap-ui依赖,生成接口文档

This commit is contained in:
hupeng
2019-09-08 10:25:04 +08:00
parent d1959f2f7a
commit 1296549d1d
5 changed files with 94 additions and 44 deletions

View File

@ -61,12 +61,23 @@
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!--防止进入swagger页面报类型转换错误排除2.9.2中的引用手动增加1.5.21版本-->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.21</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.5.21</version>
</dependency>
<dependency>
<groupId>wiki.xsx</groupId>
<artifactId>spring-boot-starter-fast-redis</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>

View File

@ -1,41 +1,41 @@
//package com.ruoyi.app.common.config;
//
//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.spi.DocumentationType;
//import springfox.documentation.spring.web.plugins.Docket;
//import springfox.documentation.swagger2.annotations.EnableSwagger2;
//
///**
// * @ClassName SwaggerConfiguration
// * @Author hupeng <610796224@qq.com>
// * @Date 2019/6/28
// **/
//
//@Configuration
//@EnableSwagger2
//public class SwaggerConfiguration {
// @Bean
// public Docket createRestApi() {
// return new Docket(DocumentationType.SWAGGER_2)
// .apiInfo(apiInfo())
// .select()
// .apis(RequestHandlerSelectors.basePackage("com.yixiang.security.modular"))
// .paths(PathSelectors.any())
// .build();
// }
//
// private ApiInfo apiInfo() {
// return new ApiInfoBuilder()
// .title("旅游系统API")
// .description("旅游系统API")
// .termsOfServiceUrl("http://localhost:8009/")
// .contact("610896224@qq.com")
// .version("1.0")
// .build();
// }
//}
package com.ruoyi.app.common.config;
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.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* @ClassName SwaggerConfiguration
* @Author hupeng <610796224@qq.com>
* @Date 2019/6/28
**/
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.ruoyi.app.modular"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("供货商城API")
.description("供货商城API")
.termsOfServiceUrl("http://localhost:8009/")
.contact("610896224@qq.com")
.version("1.0")
.build();
}
}

View File

@ -9,6 +9,8 @@ import com.ruoyi.app.common.persistence.model.StoreMember;
import com.ruoyi.app.modular.member.service.IMemberService;
import com.ruoyi.app.modular.member.service.vo.LoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
@ -25,7 +27,7 @@ import java.util.HashMap;
//@RequestMapping(value = "/")
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
//@Api(value = "认证授权模块", tags = "认证授权模块", description = "认证授权模块")
@Api(value = "认证授权模块", tags = "认证授权模块", description = "认证授权模块")
public class AuthController {
private final UserOperator userOperator;
private final JwtOperator operator;
@ -49,7 +51,7 @@ public class AuthController {
* @return token字符串
*/
@PostMapping("/oauth/access_token")
// @ApiOperation(value = "获取token",notes = "获取token")
@ApiOperation(value = "获取token",notes = "获取token")
public R loginReturnToken(@Validated @RequestBody LoginVO loginVO) {
Boolean isProduct = false;
String openid = null;

View File

@ -9,9 +9,14 @@ import com.ruoyi.app.modular.shop.service.dto.NewsDTO;
import com.ruoyi.app.modular.shop.service.impl.AdServiceImpl;
import com.ruoyi.app.modular.shop.service.impl.GoodsServiceImpl;
import com.ruoyi.app.modular.shop.service.impl.NewsServiceImpl;
import com.ruoyi.app.modular.shop.service.vo.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
@ -27,13 +32,16 @@ import java.util.Map;
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(value = "首页模块", tags = "首页模块", description = "首页模块")
public class IndexController {
private final UserOperator userOperator;
private final GoodsServiceImpl goodsService;
private final NewsServiceImpl newsService;
private final AdServiceImpl adService;
@GetMapping("/shop/index-list")
@ApiOperation(value = "首页信息",notes = "首页信息")
public R index(){
int userId = userOperator.getUser().getId();
@ -51,4 +59,12 @@ public class IndexController {
return R.success(map);
//return null;
}
@GetMapping("/shop/news-lists")
public R news(@Validated @RequestBody PageVO pageVO){
List<NewsDTO> newsList = newsService.getList(pageVO.getPage(),pageVO.getLimit());
return R.success(newsList);
}
}

View File

@ -0,0 +1,21 @@
package com.ruoyi.app.modular.shop.service.vo;
import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
@Data
public class PageVO {
//@NotBlank(message = "code必传")
@Min(message = "page为数值其值必须大于1",value = 1)
private int page;
@Min(message = "limit为数值其值必须大于1",value = 1)
private int limit;
}