java.lang.IllegalArgumentException: No property cust found for type Customer!

这个错上百度查,说是类名,接口名,或实现类类名问题,但我的错误是属性名问题,很无语的异常

                                                                             生气三秒种 

                                                            

 

原先的javaBean类

import javax.persistence.*;

@Entity
@Table(name = "cst_customer")
public class Customer {
    @Id
    @Column(name = "cust_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long cust_id;
    @Column(name = "cust_address")
    private String cust_address;
    @Column(name = "cust_industry")
    private String cust_industry;
    @Column(name = "cust_Level")
    private String cust_Level;
    @Column(name = "cust_name")
    private String cust_name;
    @Column(name = "cust_phone")
    private String cuscust_phonetPhone;
    @Column(name = "cust_source")
    private String cust_source;
    @Column(name = "cust_mobile")
    private String cust_mobile;

//此处省略getXxx() & setXxx() & toString() 方法

}

CustomerDao 是一个接口,我没有写实现类

public interface CustomerDao extends JpaRepository<Customer,Long>,JpaSpecificationExecutor<Customer> {

}

 TestCustomerDao 是一个测试类

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")

public class TestCustomerDao {
    @Autowired
    private CustomerDao customerDao;   

 @Test
    public void test7(){

    // customerDao.findAll(Specification specification,Sort sort);  查找全部数据
    //表里有几个手机号是18开头的Customer

        customerDao.findAll(

                ((root, query, criteriaBuilder) -> {
            Path<Object> cust_phone = root.get("cust_phone");
            return criteriaBuilder.like(cust_phone.as(String.class),"%18%");

        }),
                new Sort(Sort.Direction.DESC,"cust_id")
        ).forEach(customer -> System.out.println("customer = " + customer));
    }


}

 运行结果就报错:

java.lang.IllegalArgumentException:  No property cust found for type Customer!

 

解决方法:把javaBean里的属性名和表中的记录改成不一样的即可,

当然测试类的做出相应的改变

例:

  new Sort(Sort.Direction.DESC,"cust_id")  ---->  new Sort(Sort.Direction.DESC,"custId")

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值