增加对外API模块

v1.4.1
Parker 5 years ago
parent b4e494cfcc
commit e20c9316f1

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>opsli-boot-parent</artifactId>
<groupId>org.opsliframework.boot</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>opsli-api</artifactId>
<version>${project.parent.version}</version>
<dependencies>
<!-- 引入公共模块 -->
<dependency>
<groupId>org.opsliframework.boot</groupId>
<artifactId>opsli-common</artifactId>
<version>${version}</version>
</dependency>
<!-- ———————————————————— 集成SwaggerApi - 开始 ———————————————————— -->
<!-- Swagger API文档 -->
<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>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>2.9.2</version>
</dependency>
<!-- # 增加两个配置解决 NumberFormatException -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.22</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.5.22</version>
</dependency>
<!-- ———————————————————— 集成SwaggerApi - 结束 ———————————————————— -->
</dependencies>
</project>

@ -1,8 +1,7 @@
package org.opsli.common.api; package org.opsli.api.base.result;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import java.io.Serializable; import java.io.Serializable;

@ -1,7 +1,6 @@
package org.opsli.core.base.entity; package org.opsli.api.base.warpper;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ -14,7 +13,14 @@ import java.util.Date;
/** /**
* *
* Entity * Api
*
* entity web
*
* api wrapper
*
* Entity deleted WrapperModel
* WrapperModel
* *
* @author Parker * @author Parker
* @date 2019-05-11 * @date 2019-05-11
@ -23,12 +29,12 @@ import java.util.Date;
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
public abstract class BaseEntity implements Serializable { public abstract class ApiWrapper implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** ID */ /** ID */
@TableId(type = IdType.ASSIGN_ID) @TableId
@ApiModelProperty(value = "ID") @ApiModelProperty(value = "ID")
private String id; private String id;
@ -53,6 +59,8 @@ public abstract class BaseEntity implements Serializable {
private Date updateTime; private Date updateTime;
/** 乐观锁 版本 */ /** 乐观锁 版本 */
@ApiModelProperty(value = "版本")
@Version
private Integer version; private Integer version;
} }

@ -1,11 +1,13 @@
package org.opsli.core.conf; package org.opsli.api.conf;
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI; import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.opsli.api.conf.prop.ApiPathProperties;
import org.opsli.common.annotation.ApiRestController;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.ApiInfoBuilder;
@ -16,19 +18,28 @@ import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import springfox.documentation.swagger2.annotations.EnableSwagger2;
import javax.annotation.Resource;
/** /**
* @Author parker * 访
* * @author parker
* swagger
*
* spring enablefasle
*/ */
@Slf4j @Slf4j
@Configuration @Configuration
@EnableSwagger2 @EnableSwagger2
@EnableSwaggerBootstrapUI @EnableSwaggerBootstrapUI
@ConditionalOnProperty(name = "swagger.enable", havingValue = "true") public class SpringWebMvcConfig implements WebMvcConfigurer {
public class SwaggerConfig implements WebMvcConfigurer {
@Resource
private ApiPathProperties apiPathProperties;
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer
.addPathPrefix(apiPathProperties.getGlobalPrefix(),c -> c.isAnnotationPresent(ApiRestController.class));
}
// ========================= Swagger =========================
/** /**
* *
@ -54,13 +65,13 @@ public class SwaggerConfig implements WebMvcConfigurer {
.apiInfo(apiInfo()) .apiInfo(apiInfo())
.select() .select()
//此包路径下的类,才生成接口文档 //此包路径下的类,才生成接口文档
.apis(RequestHandlerSelectors.basePackage("org.opsli.modulars")) .apis(RequestHandlerSelectors.basePackage("org.opsli"))
//加了ApiOperation注解的类才生成接口文档 //加了ApiOperation注解的类才生成接口文档
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any()) .paths(PathSelectors.any())
.build(); .build();
//.securitySchemes(Collections.singletonList(securityScheme())); //.securitySchemes(Collections.singletonList(securityScheme()));
//.globalOperationParameters(setHeaderToken()); //.globalOperationParameters(setHeaderToken());
} }
/*** /***
@ -101,8 +112,8 @@ public class SwaggerConfig implements WebMvcConfigurer {
.description("后台API接口") .description("后台API接口")
// 作者 // 作者
.contact("Parker") .contact("Parker")
.license("The Apache License, Version 2.0") .license("The Apache License, Version 2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
.build(); .build();
} }

@ -1,4 +1,4 @@
package org.opsli.core.prop; package org.opsli.api.conf.prop;
import lombok.Data; import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
@ -6,7 +6,7 @@ import org.springframework.stereotype.Component;
/** /**
* *
* @author C西 * @author parker
*/ */
@Component @Component
@ConfigurationProperties(prefix = "server.servlet.api.path") @ConfigurationProperties(prefix = "server.servlet.api.path")

@ -0,0 +1,96 @@
package org.opsli.api.web.test;
import io.swagger.annotations.ApiOperation;
import org.opsli.api.base.result.ResultVo;
import org.opsli.api.wrapper.test.TestModel;
import org.opsli.common.annotation.ApiRestController;
import org.springframework.web.bind.annotation.GetMapping;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.test.web
* @Author: Parker
* @CreateTime: 2020-09-13 17:40
* @Description:
*/
@ApiRestController("/test")
public interface ITestApi {
@ApiOperation(value = "发送邮件", notes = "发送邮件")
@GetMapping("/sendMail")
ResultVo sendMail();
/**
* Redis
* @return
*/
@ApiOperation(value = "发送 Redis 订阅消息", notes = "发送 Redis 订阅消息")
@GetMapping("/sendMsg")
ResultVo sendMsg();
/**
* Redis
* @return
*/
@ApiOperation(value = "发送 Redis 测试", notes = "发送 Redis 测试")
@GetMapping("/redisTest")
ResultVo redisTest();
/**
* Redis
* @return
*/
@ApiOperation(value = "发起 Redis 分布式锁", notes = "发起 Redis 分布式锁")
@GetMapping("/testLock")
ResultVo testLock();
/**
*
* @return
*/
@ApiOperation(value = "新增数据", notes = "新增数据")
@GetMapping("/insert")
ResultVo insert(TestModel entity);
/**
*
* @return
*/
@ApiOperation(value = "修改数据", notes = "修改数据")
@GetMapping("/update")
ResultVo update(TestModel entity);
/**
*
* @return
*/
@ApiOperation(value = "查看对象", notes = "查看对象")
@GetMapping("/get")
ResultVo get(TestModel entity);
/**
*
* @return
*/
@ApiOperation(value = "删除对象", notes = "删除对象")
@GetMapping("/del")
ResultVo del(String id);
/**
*
* @return
*/
@ApiOperation(value = "删除全部对象", notes = "删除全部对象")
@GetMapping("/delAll")
ResultVo delAll();
}

@ -0,0 +1,23 @@
package org.opsli.api.wrapper.test;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.opsli.api.base.warpper.ApiWrapper;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.modulars.test.entity
* @Author: Parker
* @CreateTime: 2020-09-16 17:33
* @Description:
*/
@Data
public class TestModel extends ApiWrapper {
@ApiModelProperty(value = "名称")
private String name;
@ApiModelProperty(value = "备注")
private String remark;
}
Loading…
Cancel
Save