统一返回参数
public class R {
private Integer code;
private String msg;
private Object obj;
public static R build() {
return new R();
}
public static R ok(String msg) {
return new R(200, msg, null);
}
public static R ok(String msg, Object obj) {
return new R(200, msg, obj);
}
public static R error(String msg) {
return new R(500, msg, null);
}
public static R error(String msg, Object obj) {
return new R(500, msg, obj);
}
private R() {
}
private R(Integer code, String msg, Object obj) {
this.code = code;
this.msg = msg;
this.obj = obj;
}
public Integer getCode() {
return code;
}
public R setCode(Integer code) {
this.code = code;
return this;
}
public String getMsg() {
return msg;
}
public R setMsg(String msg) {
this.msg = msg;
return this;
}
public Object getObj() {
return obj;
}
public R setObj(Object obj) {
this.obj = obj;
return this;
}
}
启动类
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class,args);
}
}
打包类
@Configuration
@ComponentScan("com.ic.comm")
public class Rn {
}
spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.ic.comm.Rn
pom.xml
<?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>org.example</groupId>
<artifactId>springfactorys</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>provided</scope>
<version>2.7.0</version>
</dependency>
</dependencies>
</project>
install 打包
另一个项目使用