spring-data-elasticsearch查询No property ... found for...Did you mean '...'?
2018-02-06 16:26
531 查看
实体类字段定义:
dao中接口名定义:
spring-data按照接口方法定义的名字(默认认为是驼峰写法)skuNo去实体类查找对应字段,当找不到时,就报错了:
org.springframework.data.mapping.PropertyReferenceException: No property skuNo found for type Goods! Did you mean 'sku_no'?
spring-data规范要求dao中的findBy***,必须和实体字段名称一致,例如findByUdateTime,实体中也要是private String udateTime; 实体字段命名不能是sku_no这种格式,这个不符合驼峰规范。
当然,万事都有解决的办法,如果你非要使用自定义格式的字段,那么就需要特殊处理一下了。
这样就可以了。
private String sku_no;
dao中接口名定义:
Goods findBySkuNo(String skuNo);
spring-data按照接口方法定义的名字(默认认为是驼峰写法)skuNo去实体类查找对应字段,当找不到时,就报错了:
org.springframework.data.mapping.PropertyReferenceException: No property skuNo found for type Goods! Did you mean 'sku_no'?
spring-data规范要求dao中的findBy***,必须和实体字段名称一致,例如findByUdateTime,实体中也要是private String udateTime; 实体字段命名不能是sku_no这种格式,这个不符合驼峰规范。
当然,万事都有解决的办法,如果你非要使用自定义格式的字段,那么就需要特殊处理一下了。
@Query("{\"bool\" : {\"must\" : {\"term\" : {\"sku_no\" : \"?0\"}}}}") Goods findBySkuNo(String skuNo);
这样就可以了。
相关文章推荐
- Spring Data JPA: No property foo found for type Bar
- Spring Data JPA: No property name found for type ×××
- Spring Data JPA - “No Property Found for Type” Exception
- org.springframework.data.mapping.model.MappingException: No id property found for object of type
- org.springframework.data.mapping.PropertyReferenceException: No property created found for type
- Spring Data JPA 报错 :PropertyReferenceException: No property params found for type xxx!
- org.springframework.data.mapping.PropertyReferenceException: No property xxxx found for type Xxxx
- Caused by: org.springframework.data.mapping.PropertyReferenceException: No property name found for t
- adb的问题“No command ‘adb’ found, did you mean:”
- No setter found for property 'mapperLocation' in class 'org.mybatis.spring.SqlSessionFactoryBean' [c
- adb的问题“No command 'adb' found, did you mean:”
- no setter found for property(spring xml文件property标签中)错误的解决方法
- Spring Data Jpa 异常:PropertyReferenceException: No property xx for type yy
- Spring Data JPA 全局DAO的扩展(第一次用JPA时总是提示 另人抓狂的错误: No property find for type class )
- No SDKs could be found for the IOS Device Platform, did you install the command line tools on your
- active spring整合 but no declaration can be found for element amq:broker
- Spring的JUnit错误:NoSuchBeanDefinitionException: No unique bean of type,expected single matching bean but found 2 [dataSource1,data
- vtk 使用静态版本出现no override found for vtkpolydatamapper
- 访问Storm ui界面,出现org.apache.storm.utils.NimbusLeaderNotFoundException: Could not find leader nimbus from seed hosts ["master"]. Did you specify a valid list of nimbus hosts for confi的问题解决(图文详解)
- Spring MVC No mapping found for HTTP request with URI