你好,我想创建一个方法来执行以下查询
SELECT * FROM Customer where customer.customerpremium=true;
我很累实现这种方法,但是不起作用。
public interface CustomerRepository extends CrudRepository<Customer, String>{
Iterable<Customer> findByCustomerPremium(boolean customerpremium);
}
关注我的实体
@Entity
@Table(name = "customer")
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
@Column(name = "customerid")
private Integer customerid;
@NotEmpty
@Column(name = "customername")
private String customername;
@NotEmpty
@Column(name = "customeremail")
private String customeremail;
@Column(name = "customerpremium")
private boolean customerpremium;
/**gets and sets*/
}
答案 0 :(得分:1)
您的财产在小写情况下customerpremium
尝试
Iterable<Customer> findByCustomerpremium(boolean customerpremium);
当前这种方法
Iterable<Customer> findByCustomerPremium(boolean customerpremium);
创建这样的查询
SELECT * FROM Customer where customer.customer_premium=:customerpremium;
您还可以通过在application.properties
文件中添加以下行来记录您的SQL查询
spring.jpa.show-sql=true