小编Dan*_*ing的帖子

加上这个.IntelliJ Idea中的成员变量/方法

IntelliJ Idea中是否有办法强制执行此操作.自动放入格式代码或保存或至少显示错误,如果它应该在那里?

intellij-idea

16
推荐指数
1
解决办法
3550
查看次数

组合弹簧数据规范的查询在同一个表上有多个连接

对不起,如果我的术语不正确.

我们使用spring数据,JpaRepositories和条件查询作为查询数据库数据的方法.

我有一个问题,当我在下面的代码示例中结合两个规范,例如我在hasCityAndTimeZone中使用hasTimeZone和hasCity时,它会在同一个表上连接两次,所以下面的查询看起来像

select * from Staff, Location, Location
Run Code Online (Sandbox Code Playgroud)

有没有办法让这两个规范使用相同的连接而不是每个定义它们自己的连接基本相同?

对不起代码可能不完整我只是想展示一个简单的例子.

class Staff {
    private Integer id;
    private Location location;
}

class Location {
    private Integer id; 
    private Integer timeZone;
    private Integer city;
}

class StaffSpecs {
    public static Specification<Staff> hasTimeZone(Integer timeZone) {
        return new Specification<Staff>() {
            @Override
            public Predicate toPredicate(Root<Staff> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                Path<Integer> timeZonePath = root.join(Staff_.location).get(Location_.timeZone);
                return cb.equal(timeZonePath, timeZone);
            }
        }
    }

    public static Specification<Staff> hasCity(Integer city) {
        return new Specification<Staff>() {
            @Override
            public Predicate …
Run Code Online (Sandbox Code Playgroud)

spring jpa spring-data spring-data-jpa

6
推荐指数
1
解决办法
1万
查看次数