假设我有实体(为简洁起见,省略了getter / setter和各种细节):

@Entity
class Customer{
    ...
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "customer")
    Collection<Coupon> coupons;
}

@Entity
class Coupon{
    ...
    @Temporal(value = TemporalType.TIMESTAMP)
    private Date usedOn;

    @ManyToOne(fetch = FetchType.LAZY)
    @NotNull
    Customer customer;
}

我希望为null为null的给定客户检索所有优惠券。
我尚未按照docs中的说明在CouponRepository中定义一个方法,但未成功
@Repository
public interface CouponRepository extends CrudRepository<Coupon, Long> {
     Collection<Coupon> findByCustomerAndUsedOnIsNull(Customer);
}

但这会导致编译器错误Syntax error, insert "... VariableDeclaratorId" to complete FormalParameterList

最佳答案

我的错,正确的定义是

@Repository
public interface CouponRepository extends CrudRepository<Coupon, Long> {
     Collection<Coupon> findByCustomerAndUsedOnIsNull(Customer customer);
}

我只是错过了参数名称:-(

关于spring - Spring数据查询,其中column为空,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29448282/

10-09 19:29