如何使用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 class 导入 userApplication。然后使用 feign 调用 userData 服务获取 UserData 数据。搞定之后,就可以使用apache BeanUtils将UserData obj复制到ApplicationUser obj中了。
我正在使用微服务架构,我正在尝试创建一个 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 class 导入 userApplication。然后使用 feign 调用 userData 服务获取 UserData 数据。搞定之后,就可以使用apache BeanUtils将UserData obj复制到ApplicationUser obj中了。