我希望使用jpa repository和规范。
现在我有两个表格。
@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);
}
};
}
}
所以,我的问题是:在表格区域中,我需要放入什么内容来代替“?????”?