简体   繁体   English

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

[英]How to create two entities using springboot microservices

I'm using a microservices architecture, and I'm trying to create a userApplication entity which has all data necessary for a credential purpose only, that means basic info about my user, also i have another entity userData which have all the data for my current application, so i dont really sure how to match those two and also call userData service when i create a userApplication entity because each one has his own microservice我正在使用微服务架构,并且我正在尝试创建一个 userApplication 实体,该实体仅包含用于凭据目的所需的所有数据,这意味着有关我的用户的基本信息,我还有另一个实体 userData,其中包含我的所有数据当前的应用程序,所以我不确定如何匹配这两者并在创建 userApplication 实体时调用 userData 服务,因为每个实体都有自己的微服务

I tried to use Feign but I'm not sure how to do it.我尝试使用 Feign,但我不知道该怎么做。

//ApplicationUser //应用用户

@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;

//UserData //用户数据

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;

//repository //存储库

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

    public ApplicationUser findByUsername(String username);

    public  ApplicationUser CreateUserWithData ();
}

In my experience, you should import UserData class into userApplication.根据我的经验,您应该将 UserData 类导入到 userApplication 中。 Then use feign to invoke userData service to get UserData datas.然后使用feign调用userData服务获取UserData数据。 After doing it, you can use apache BeanUtils to copy UserData obj to ApplicationUser obj.完成后,您可以使用apache BeanUtils 将UserData obj 复制到ApplicationUser obj。

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

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