数据库结构
CREATE TABLE t_demo_user(
id VARCHAR(90) NOT NULL,
username VARCHAR(90) NOT NULL,
password VARCHAR(90) NOT NULL,
address_city VARCHAR(90) NOT NULL,
address_distinct VARCHAR(90) NOT NULL,
address_street VARCHAR(90) NOT NULL,
address_unit VARCHAR(90) NOT NULL,
address_number VARCHAR(90) NOT NULL,
PRIMARY KEY (id)
);
领域对象 User
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "t_demo_user")
public class User {
@EmbeddedId private UserId userId;
private String username;
private String password;
@Embedded private Address address;
}
ID对象 UserId
@Data
@Embeddable
public class UserId implements java.io.Serializable {
@Column(name = "id")
@GeneratedValue
private String value;
}
值对象 Address
@Data
@Embeddable
public class Address {
@Column(name = "address_city")
private String city;
@Column(name = "address_distinct")
private String distinct;
@Column(name = "address_street")
private String street;
@Column(name = "address_unit")
private String unit;
@Column(name = "address_number")
private String number;
}
本文由 Ivan Dong 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Jun 25, 2023 at 09:47 am