Commit 15461b6e authored by 李成龙's avatar 李成龙

增加swagger文档

parent e5bcd2f2
......@@ -16,6 +16,12 @@
</parent>
<dependencies>
<!-- knife4j -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j-spring-boot-starter.version}</version>
</dependency>
</dependencies>
</project>
package com.yeejoin.amos.boot.biz.common.constants;
/**
* @Description: 通用常量类
* @Author: DELL
* @Date: 2021/5/26
*/
public interface CommonConstant {
/**
* 成功状态
*/
public final static String RESULT_SUCCESS = "SUCCESS";
/**
* 失败状态
*/
public final static String RESULT_FAILURE = "FAILURE";
public final static String X_ACCESS_TOKEN = "X-Access-Token";
}
package org.amos.boot.biz.common.controller;
package com.yeejoin.amos.boot.biz.common.controller;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.component.feign.config.InnerInvokException;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import org.amos.boot.biz.common.bo.ReginParams;
import org.amos.boot.biz.common.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.TransactionSystemException;
import org.springframework.web.bind.annotation.RequestMapping;
......
package org.amos.boot.biz.common.dao.mapper;
package com.yeejoin.amos.boot.biz.common.dao.mapper;
import org.apache.ibatis.annotations.Mapper;
......
package org.amos.boot.biz.common.entity;
package com.yeejoin.amos.boot.biz.common.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
......
package org.amos.boot.biz.common.utils;
package com.yeejoin.amos.boot.biz.common.utils;
import org.amos.boot.biz.common.constants.CommonConstant;
import org.springframework.http.HttpStatus;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import com.yeejoin.amos.boot.biz.common.constants.CommonConstant;
/**
* @author DELL
*/
......
package org.amos.boot.biz.common.utils;
package com.yeejoin.amos.boot.biz.common.utils;
import org.apache.commons.lang3.StringUtils;
......
package org.amos.boot.biz.common.utils;
package com.yeejoin.amos.boot.biz.common.utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
......
package com.yeejoin.amos.boot.biz.config;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.yeejoin.amos.boot.biz.common.constants.CommonConstant;
import io.swagger.annotations.ApiOperation;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.AuthorizationScope;
import springfox.documentation.service.Parameter;
import springfox.documentation.service.SecurityReference;
import springfox.documentation.service.SecurityScheme;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* @Author lichenglong
*/
@Configuration
@EnableSwagger2
@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
public class Swagger2Config implements WebMvcConfigurer {
/**
*
* 显示swagger-ui.html文档展示页,还必须注入swagger资源:
*
* @param registry
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
/**
* swagger2的配置文件,这里可以配置swagger2的一些基本的内容,比如扫描的包等等
*
* @return Docket
*/
@Bean(value = "defaultApi2")
public Docket defaultApi2() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("amos业务服务接口")
.apiInfo(apiInfo())
.select()
//此包路径下的类,才生成接口文档
.apis(RequestHandlerSelectors.basePackage("com.yeejoin.amos"))
//加了ApiOperation注解的类,才生成接口文档
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build()
.securitySchemes(Collections.singletonList(securityScheme()))
.securityContexts(securityContexts());
//.globalOperationParameters(setHeaderToken());
}
/***
* oauth2配置
* 需要增加swagger授权回调地址
* http://localhost:8888/webjars/springfox-swagger-ui/o2c.html
* @return
*/
@Bean
SecurityScheme securityScheme() {
return new ApiKey(CommonConstant.X_ACCESS_TOKEN, CommonConstant.X_ACCESS_TOKEN, "header");
}
/**
* JWT token
* @return
*/
private List<Parameter> setHeaderToken() {
ParameterBuilder tokenPar = new ParameterBuilder();
List<Parameter> pars = new ArrayList<>();
tokenPar.name(CommonConstant.X_ACCESS_TOKEN).description("token").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
pars.add(tokenPar.build());
return pars;
}
/**
* api文档的详细信息函数,注意这里的注解引用的是哪个
*
* @return
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
// //大标题
.title("amos-boot-biz 后台服务API接口文档")
// 版本号
.version("1.0")
// .termsOfServiceUrl("NO terms of service")
// 描述
.description("后台API接口")
// 作者
.contact("Amos业务团队")
.license("The Apache License, Version 2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
.build();
}
/**
* 新增 securityContexts 保持登录状态
*/
private List<SecurityContext> securityContexts() {
return new ArrayList(
Collections.singleton(SecurityContext.builder()
.securityReferences(defaultAuth())
.forPaths(PathSelectors.regex("^(?!auth).*$"))
.build())
);
}
private List<SecurityReference> defaultAuth() {
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
return new ArrayList(
Collections.singleton(new SecurityReference(CommonConstant.X_ACCESS_TOKEN, authorizationScopes)));
}
}
package org.amos.boot.biz.common.constants;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.time.format.DateTimeFormatter;
/**
* @Description: 通用常量类
* @Author: DELL
* @Date: 2021/5/26
*/
public interface CommonConstant {
String RESULT_SUCCESS = "SUCCESS";
String RESULT_FAILURE = "FAILURE";
}
......@@ -36,8 +36,8 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
"org.typroject.tyboot.face.*.orm.dao*",
"org.typroject.tyboot.core.auth.face.orm.dao*",
"org.typroject.tyboot.component.*.face.orm.dao*",
"org.amos.boot.module.jcs.api.mapper"})
@ComponentScan(basePackages = { "org.amos.boot", "org.typroject", "com.yeejoin.amos" })
"com.yeejoin.amos.boot.module.jcs.api.mapper"})
@ComponentScan(basePackages = { "org.typroject", "com.yeejoin.amos" })
public class AmosJcsApplication
{
private static final Logger logger = LoggerFactory.getLogger(AmosJcsApplication.class);
......
spring.application.name=AIRPORT
server.servlet.context-path=/airPort
server.port=11000
spring.profiles.active=dev
\ No newline at end of file
spring.profiles.active=dev
#swagger开启
#swagger.enable=true
# 是否停用Knife4j文档
knife4j.production=false
knife4j.basic.enable=false
#knife4j.basic.username=jeecg
#knife4j.basic.password=jeecg1314
\ No newline at end of file
package org.amos.boot.module.jcs.api.entity;
package com.yeejoin.amos.boot.module.jcs.api.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
......
package org.amos.boot.module.jcs.api.mapper;
package com.yeejoin.amos.boot.module.jcs.api.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.amos.boot.module.jcs.api.entity.CbDemo;
import com.yeejoin.amos.boot.module.jcs.api.entity.CbDemo;
/**
* @Description: 示例代码
* @Author: amos-boot-biz
......
package org.amos.boot.module.jcs.api.service;
import org.amos.boot.module.jcs.api.entity.CbDemo;
package com.yeejoin.amos.boot.module.jcs.api.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yeejoin.amos.boot.module.jcs.api.entity.CbDemo;
/**
* <p>
*示例 服务类
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.amos.boot.module.jcs.api.mapper.DemoMapper">
<select id="selectOneBySeqNbr" resultType="org.amos.boot.module.jcs.api.entity.CbDemo">
<mapper namespace="com.yeejoin.amos.boot.module.jcs.api.mapper.DemoMapper">
<select id="selectOneBySeqNbr" resultType="com.yeejoin.amos.boot.module.jcs.api.entity.CbDemo">
select * from tb_demo where sequence_nbr = #{seqNbr};
</select>
</mapper>
package org.amos.boot.module.jcs.biz.controller;
package com.yeejoin.amos.boot.module.jcs.biz.controller;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.amos.boot.biz.common.controller.BaseController;
import org.amos.boot.biz.common.utils.CommonResponseUtil;
import org.amos.boot.module.jcs.api.entity.CbDemo;
import org.amos.boot.module.jcs.api.service.IDemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -15,6 +12,11 @@ import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.biz.common.utils.CommonResponseUtil;
import com.yeejoin.amos.boot.module.jcs.api.entity.CbDemo;
import com.yeejoin.amos.boot.module.jcs.api.service.IDemoService;
import java.util.List;
/**
......
package org.amos.boot.module.jcs.biz.service.impl;
package com.yeejoin.amos.boot.module.jcs.biz.service.impl;
import org.amos.boot.module.jcs.api.entity.CbDemo;
import org.amos.boot.module.jcs.api.mapper.DemoMapper;
import org.amos.boot.module.jcs.api.service.IDemoService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yeejoin.amos.boot.module.jcs.api.entity.CbDemo;
import com.yeejoin.amos.boot.module.jcs.api.mapper.DemoMapper;
import com.yeejoin.amos.boot.module.jcs.api.service.IDemoService;
import lombok.extern.slf4j.Slf4j;
/**
......
......@@ -38,8 +38,8 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
"org.typroject.tyboot.face.*.orm.dao*",
"org.typroject.tyboot.core.auth.face.orm.dao*",
"org.typroject.tyboot.component.*.face.orm.dao*",
"org.amos.boot.module.tzs.biz.dao.mapper"})
@ComponentScan(basePackages = { "org.amos.boot", "org.typroject", "com.yeejoin.amos" })
"com.yeejoin.amos.boot.module.tzs.biz.dao.mapper"})
@ComponentScan(basePackages = { "org.typroject", "com.yeejoin.amos" })
public class AmosTzsApplication {
private static final Logger logger = LoggerFactory.getLogger(AmosTzsApplication.class);
......
......@@ -16,6 +16,8 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<fastjson.version>1.2.75</fastjson.version>
<knife4j-spring-boot-starter.version>2.0.4</knife4j-spring-boot-starter.version>
<knife4j-spring-ui.version>2.0.4</knife4j-spring-ui.version>
<springboot.version>2.1.6.RELEASE</springboot.version>
<springcloud.version>Greenwich.SR1</springcloud.version>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
......@@ -146,31 +148,6 @@
<artifactId>httpcore</artifactId>
</dependency>
<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>
<!-- 防止一直报错 -->
<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>org.liquibase</groupId>-->
<!-- <artifactId>liquibase-core</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
</dependency>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment