繁体   English   中英

如何使用 springboot 微服务创建两个实体

[英]How to create two entities using springboot microservices

我正在使用微服务架构,并且我正在尝试创建一个 userApplication 实体,该实体仅包含用于凭据目的所需的所有数据,这意味着有关我的用户的基本信息,我还有另一个实体 userData,其中包含我的所有数据当前的应用程序,所以我不确定如何匹配这两者并在创建 userApplication 实体时调用 userData 服务,因为每个实体都有自己的微服务

我尝试使用 Feign,但我不知道该怎么做。

//应用用户

@Id
    @GeneratedValue(generator = "UUID")
    @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
    @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
    private UUID id;

    @Column(unique = true, length = 20)
    private String username;
    private String normalizedUsername;

    @Column(length = 60)
    private String password;
    private Boolean enabled;
    private String firstname;
    private String lastname;

    @Column(unique = true, length = 100)
    private String email;
    private Boolean emailConfirmed;
    private String normalizedEmail;
    private String phonenumber;
    private Boolean phonenumberConfirmed;
    private Boolean twoFactorEnabled;

    @OneToMany(mappedBy = "id")
    @Column(name = "user_datum", table = "user_data")
    private Collection<UserData> userDatum;

//用户数据

private String email;
    private String firstname;
    private String lastname;
    private String address;
    private LocalDate birthday;
    private Double height;
    private Double weight;
    private String bloodType;
    private String city;
    private String country;

    @ManyToOne()
    @PrimaryKeyJoinColumn(name = "id")
    private ApplicationUser user;

//存储库

    @RepositoryRestResource(path = "users")
public interface UserRepository extends JpaRepository<ApplicationUser, UUID> {

    public ApplicationUser findByUsername(String username);

    public  ApplicationUser CreateUserWithData ();
}

根据我的经验,您应该将 UserData 类导入到 userApplication 中。 然后使用feign调用userData服务获取UserData数据。 完成后,您可以使用apache BeanUtils 将UserData obj 复制到ApplicationUser obj。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM