【发布时间】:2019-01-24 08:03:53
【问题描述】:
我正在尝试使用 Spring Data MongoRepository 访问 mongodb 数据层。所以在这里我可以使用存储库端点进行基本的 CRUD 操作,但无法进行自定义搜索。
模型类:
@Document(collection = "merchant")
public class Merchant {
@Id
private String id;
private Long zohoAccountRefId;
private String businessId;
private String businessName;
private String businessAddress;
private String businessPhone;
private String description;
private String businessEmail;
private String accountType;
private BusinessOwner businessOwner;
private List<Product> products;
private List<Plugin> plugins;
private List<Service> services;
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private Date dateCreated;
//getters and setters
}
存储库:
@RepositoryRestResource(collectionResourceRel = "account",path = "account")
public interface MerchantRepository extends MongoRepository<Merchant,String> {
@RestResource(path = "businessName",rel = "businessName")
List<Merchant> findByName(@Param("businessName") String businessName);
}
当我尝试使用此代码时,我收到以下错误:
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property name found for type Merchant!
这是实现此功能的正确方法吗?或者我得到的这个问题的解决方案是什么?
【问题讨论】:
标签: spring-data spring-data-mongodb spring-data-rest spring-repositories