有没有一种方法可以在SpringBoot中连接表而不使用类型不安全的普通sql字符串?目前正在使用jbdc。
这里的这些方法不是字符串安全的:在SpringDataJPA中连接两个表实体
在.net中,实体框架在c中有一个方法#
from u in db.Users
join ad in db.Address on u.Addressid equals ad.AddressId
select ..
java示例:
@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
//...
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "address_id", referencedColumnName = "id")
private Address address;
// ... getters and setters
}
@Entity
@Table(name = "address")
public class Address {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
//...
@OneToOne(mappedBy = "address")
private User user;
//... getters and setters
}
暂无答案!
目前还没有任何答案,快来回答吧!