public class City {
private String name;
private Country country;
}
public class Country {
private String name;
}
public class CitySpecification {
public Predicate findWithCountryName(Root<City> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Join join = root.join("country", JoinType.LEFT);
return cb.equal(join.get("name"), criteria.getValue());
}
谓词应将城市名称与最后一行中给定的输入相匹配,但是要获取城市名称,因为两个类都有名称字段。