微服务SpringCloud整合四

上一篇我们发现有重复的代码,所以我们需要抽出公共的代码,新建 pcloud-api-commons模块。
微服务SpringCloud整合四
微服务SpringCloud整合四
修改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>

如图
微服务SpringCloud整合四
新建model 目录
微服务SpringCloud整合四

新建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命令
微服务SpringCloud整合四
删除原来项目中的model 目录
微服务SpringCloud整合四
添加依赖
微服务SpringCloud整合四
重新 启动项目测试:
http://localhost:80/consumer/login/get/1
微服务SpringCloud整合四
整合完成

上一篇:(每日一练c++)统计某一单科成绩各分数段的分布人数


下一篇:oracle plsql手动修改数据