forked from iVMiku/guidance-backend
repo init
This commit is contained in:
31
commons/pom.xml
Normal file
31
commons/pom.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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>
|
||||
<parent>
|
||||
<groupId>com.ivmiku.tutorial</groupId>
|
||||
<artifactId>first-tutorial</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>commons</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.ivmiku.tutorial.response;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Result implements Serializable {
|
||||
@JSONField(ordinal = 1)
|
||||
private int code;
|
||||
@JSONField(ordinal = 2)
|
||||
private String message;
|
||||
@JSONField(ordinal = 3)
|
||||
private Object data = null;
|
||||
|
||||
public Result(ResultCode resultCode) {
|
||||
this.code = resultCode.getCode();
|
||||
this.message = resultCode.getMessage();
|
||||
}
|
||||
|
||||
public Result(ResultCode resultCode, Object data) {
|
||||
this.code = resultCode.getCode();
|
||||
this.message = resultCode.getMessage();
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static Result ok(){
|
||||
return new Result(200, "success", null);
|
||||
}
|
||||
|
||||
public static Result error(){
|
||||
return new Result(-1, "error", null);
|
||||
}
|
||||
|
||||
public static Result ok(Object data){
|
||||
return new Result(200, "success", data);
|
||||
}
|
||||
|
||||
public static Result ok(String message){
|
||||
return new Result(200, message, null);
|
||||
}
|
||||
|
||||
public static Result error(String message){
|
||||
return new Result(-1, message, null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.ivmiku.tutorial.response;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum ResultCode {
|
||||
OK(200, "success"),
|
||||
ERROR(-1, "error");
|
||||
|
||||
private int code;
|
||||
private String message;
|
||||
|
||||
ResultCode(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user