本文介绍了Spring数据查询,其中column为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有实体(为简便起见,省略了getters/setter和各种详细信息):

Suppose I have entities (getters/setters and various details omitted for brevity):

@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 usedOn为空的给定客户的所有优惠券.我没有成功在CouponRepository中定义方法,如文档

I wish retrieve all Coupons for a given Customer having null usedOn.I,'ve unsuccessfully defined a method in the CouponRepository as described in docs

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

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

but this leads on a compiler error Syntax error, insert "... VariableDeclaratorId" to complete FormalParameterList.

推荐答案

我的错,正确的定义是

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

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

I simply missed the parameter name :-(

这篇关于Spring数据查询,其中column为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 01:34