網上找的案例是:
實體類字段定義:
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這種格式,這個不符合駝峰規范。
我項目啟動報錯No property name found for EsProduct
因為findByNameOrSubTitleOrKeywords接口沒有使用也沒有注釋掉,改了實體類
/**
* 商品ES操作類
* Created by macro on 2018/6/19.
*/
public interface EsProductRepository extends ElasticsearchRepository<EsProduct, Long> {
/**
* 搜索查詢
*
* @param name 商品名稱
* @param subTitle 商品標題
* @param keywords 商品關鍵字
* @param page 分頁信息
* @return
*/
Page<EsProduct> findByNameOrSubTitleOrKeywords(String name, String subTitle, String keywords,Pageable page);
}
而我的EsProduct實體類中沒有name
/**
* 搜索中的商品信息
* Created by macro on 2018/6/19.
*/
@Document(indexName = "pms", type = "product",shards = 1,replicas = 0)
public class EsProduct implements Serializable {
private static final long serialVersionUID = -1L;
@Id
private Long id;
@Field(type = FieldType.Keyword)
private String productSn;
private Long brandId;
@Field(type = FieldType.Keyword)
private String brandName;
private Long productCategoryId;
@Field(analyzer = "ik_max_word",type = FieldType.Text)
private String productName;
@Field(analyzer = "ik_max_word",type = FieldType.Text)
private String subTitle;
private BigDecimal price;
@Field(analyzer = "ik_max_word",type = FieldType.Text)
private String keywords;
@Field(type =FieldType.Nested)
private List<EsProductAttribute> attriList;
@Field(type =FieldType.Nested)
private EsProductCategory productCategorie;
導致報錯