上一篇我们发现有重复的代码,所以我们需要抽出公共的代码,新建 pcloud-api-commons模块。
修改pom文件
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
如图
新建model 目录
新建user实体类
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User implements Serializable {
private Long id;
private String name;
}
新建result结果封装类
package com.younger.springcloud.model;
public class Result<T>{
private Integer code;
private String message;
private T data;
public Result() {}
public Result(Integer code, String message, T data) {
this.code = code;
this.message = message;
this.data = data;
}
public Result( Integer code,String message) {
this( code, message,null);
}
public Result(T data) {
this(200, "操作成功", data);
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
}
执行mavne install命令
删除原来项目中的model 目录
添加依赖
重新 启动项目测试:
http://localhost:80/consumer/login/get/1
整合完成