我想使用带有规范的 jpa 存储库
现在我有两张桌子
@Entity
@Table(name="user")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private Long idUser;
private Area area;
@Id @GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="iduser")
public Long getIdUser() {
return idUser;
}
public void setIdUser(Long idUser) {
this.idUser = idUser;
}
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn(name="idarea")
public Area getArea() {
return area;
}
public void setArea(Area area) {
this.area = area;
}
}
和面积表
@Entity
@Table(name = "area")
public class Area {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="idarea")
private Long idArea;
@Column(name="area_name")
private String areaName;
public Long getIdArea() {
return idArea;
}
public void setIdArea(Long idArea) {
this.idArea = idArea;
}
public String getAreaName() {
return areaName;
}
public void setAreaName(String areaName) {
this.areaName = areaName;
}
}
然后我有用户存储库,它也扩展了 JpaSpecificationExecutor
public interface UserRepository extends CrudRepository<User,Long>,JpaSpecificationExecutor<User> {
}
最后我有一个简单的规范
public class UserSpecification {
public static Specification<User> findByAreaName(final String areaName){
return new Specification<User>() {
@Override
public Predicate toPredicate(Root<User> root,
CriteriaQuery<?> criteria, CriteriaBuilder cb) {
return cb.equal(root.<String>get("??????"),areaName);
}
};
}
}
所以,我的问题是:我必须在“??????” 那是表区域的areaName?