-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08902f0
commit 020c9b7
Showing
30 changed files
with
984 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
HELP.md | ||
/target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
/build/ | ||
|
||
### VS Code ### | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.macro.mall</groupId> | ||
<artifactId>mall-tiny-mapstruct</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>mall-tiny-mapstruct</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<java.version>1.8</java.version> | ||
<mapstruct.version>1.4.2.Final</mapstruct.version> | ||
<skipTests>true</skipTests> | ||
</properties> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.3.0.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<dependencies> | ||
<!--SpringBoot通用依赖模块--> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-aop</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<!--springfox swagger官方Starter--> | ||
<dependency> | ||
<groupId>io.springfox</groupId> | ||
<artifactId>springfox-boot-starter</artifactId> | ||
<version>3.0.0</version> | ||
</dependency> | ||
<!--lombok依赖--> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<!--Hutool Java工具包--> | ||
<dependency> | ||
<groupId>cn.hutool</groupId> | ||
<artifactId>hutool-all</artifactId> | ||
<version>4.5.7</version> | ||
</dependency> | ||
<!--MapStruct相关依赖--> | ||
<dependency> | ||
<groupId>org.mapstruct</groupId> | ||
<artifactId>mapstruct</artifactId> | ||
<version>${mapstruct.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mapstruct</groupId> | ||
<artifactId>mapstruct-processor</artifactId> | ||
<version>${mapstruct.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
mall-tiny-mapstruct/src/main/java/com/macro/mall/tiny/MallTinyApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.macro.mall.tiny; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class MallTinyApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(MallTinyApplication.class, args); | ||
} | ||
|
||
} |
115 changes: 115 additions & 0 deletions
115
mall-tiny-mapstruct/src/main/java/com/macro/mall/tiny/common/api/CommonResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package com.macro.mall.tiny.common.api; | ||
|
||
/** | ||
* 通用返回对象 | ||
* Created by macro on 2019/4/19. | ||
*/ | ||
public class CommonResult<T> { | ||
private long code; | ||
private String message; | ||
private T data; | ||
|
||
protected CommonResult() { | ||
} | ||
|
||
protected CommonResult(long code, String message, T data) { | ||
this.code = code; | ||
this.message = message; | ||
this.data = data; | ||
} | ||
|
||
/** | ||
* 成功返回结果 | ||
* | ||
* @param data 获取的数据 | ||
*/ | ||
public static <T> CommonResult<T> success(T data) { | ||
return new CommonResult<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data); | ||
} | ||
|
||
/** | ||
* 成功返回结果 | ||
* | ||
* @param data 获取的数据 | ||
* @param message 提示信息 | ||
*/ | ||
public static <T> CommonResult<T> success(T data, String message) { | ||
return new CommonResult<T>(ResultCode.SUCCESS.getCode(), message, data); | ||
} | ||
|
||
/** | ||
* 失败返回结果 | ||
* @param errorCode 错误码 | ||
*/ | ||
public static <T> CommonResult<T> failed(IErrorCode errorCode) { | ||
return new CommonResult<T>(errorCode.getCode(), errorCode.getMessage(), null); | ||
} | ||
|
||
/** | ||
* 失败返回结果 | ||
* @param message 提示信息 | ||
*/ | ||
public static <T> CommonResult<T> failed(String message) { | ||
return new CommonResult<T>(ResultCode.FAILED.getCode(), message, null); | ||
} | ||
|
||
/** | ||
* 失败返回结果 | ||
*/ | ||
public static <T> CommonResult<T> failed() { | ||
return failed(ResultCode.FAILED); | ||
} | ||
|
||
/** | ||
* 参数验证失败返回结果 | ||
*/ | ||
public static <T> CommonResult<T> validateFailed() { | ||
return failed(ResultCode.VALIDATE_FAILED); | ||
} | ||
|
||
/** | ||
* 参数验证失败返回结果 | ||
* @param message 提示信息 | ||
*/ | ||
public static <T> CommonResult<T> validateFailed(String message) { | ||
return new CommonResult<T>(ResultCode.VALIDATE_FAILED.getCode(), message, null); | ||
} | ||
|
||
/** | ||
* 未登录返回结果 | ||
*/ | ||
public static <T> CommonResult<T> unauthorized(T data) { | ||
return new CommonResult<T>(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data); | ||
} | ||
|
||
/** | ||
* 未授权返回结果 | ||
*/ | ||
public static <T> CommonResult<T> forbidden(T data) { | ||
return new CommonResult<T>(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data); | ||
} | ||
|
||
public long getCode() { | ||
return code; | ||
} | ||
|
||
public void setCode(long code) { | ||
this.code = code; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
public T getData() { | ||
return data; | ||
} | ||
|
||
public void setData(T data) { | ||
this.data = data; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
mall-tiny-mapstruct/src/main/java/com/macro/mall/tiny/common/api/IErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.macro.mall.tiny.common.api; | ||
|
||
/** | ||
* 封装API的错误码 | ||
* Created by macro on 2019/4/19. | ||
*/ | ||
public interface IErrorCode { | ||
long getCode(); | ||
|
||
String getMessage(); | ||
} |
28 changes: 28 additions & 0 deletions
28
mall-tiny-mapstruct/src/main/java/com/macro/mall/tiny/common/api/ResultCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.macro.mall.tiny.common.api; | ||
|
||
/** | ||
* 枚举了一些常用API操作码 | ||
* Created by macro on 2019/4/19. | ||
*/ | ||
public enum ResultCode implements IErrorCode { | ||
SUCCESS(200, "操作成功"), | ||
FAILED(500, "操作失败"), | ||
VALIDATE_FAILED(404, "参数检验失败"), | ||
UNAUTHORIZED(401, "暂未登录或token已经过期"), | ||
FORBIDDEN(403, "没有相关权限"); | ||
private long code; | ||
private String message; | ||
|
||
private ResultCode(long code, String message) { | ||
this.code = code; | ||
this.message = message; | ||
} | ||
|
||
public long getCode() { | ||
return code; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
mall-tiny-mapstruct/src/main/java/com/macro/mall/tiny/config/Swagger2Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.macro.mall.tiny.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.service.Contact; | ||
import springfox.documentation.spi.DocumentationType; | ||
import springfox.documentation.spring.web.plugins.Docket; | ||
import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
|
||
/** | ||
* Swagger2API文档的配置 | ||
*/ | ||
@Configuration | ||
@EnableSwagger2 | ||
public class Swagger2Config { | ||
@Bean | ||
public Docket createRestApi(){ | ||
return new Docket(DocumentationType.SWAGGER_2) | ||
.apiInfo(apiInfo()) | ||
.select() | ||
//为当前包下controller生成API文档 | ||
.apis(RequestHandlerSelectors.basePackage("com.macro.mall.tiny.controller")) | ||
//为有@Api注解的Controller生成API文档 | ||
// .apis(RequestHandlerSelectors.withClassAnnotation(Api.class)) | ||
//为有@ApiOperation注解的方法生成API文档 | ||
// .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) | ||
.paths(PathSelectors.any()) | ||
.build(); | ||
} | ||
|
||
private ApiInfo apiInfo() { | ||
return new ApiInfoBuilder() | ||
.title("SwaggerUI演示") | ||
.description("mall-tiny") | ||
.contact(new Contact("macro", null, null)) | ||
.version("1.0") | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.