我有包含字段日期publicationDate和布尔档案的实体组合。我想在date作为参数传递并将archival标志设置为false之前获取具有publicationDate的Compositions列表。在完成了一些'从方法名称'教程和文档中创建查询后,我提出了方法
@Projection(types = SuperClass.class)
public interface SuperClassProjection {
Long getId();
}
或
List<Composition> findByPublicationDateBeforeDateAndArchivalFalse(Date date);
但这一切都不起作用。两者都使用
给出UnsatisfiedDependencyExceptionList<Composition> findByPublicationDateBeforeDateAndArchivalFalse(@Param("date")Date date);
Intellij还强调了BeforeDate,因为它无法解析beforeDate之前的属性。使用带参数的关键字的正确方法是什么,因此可以通过Spring将参数与字段区分开来?
答案 0 :(得分:1)
将您的方法重构为以下内容:
List<Composition> findByPublicationDateBeforeAndArchivalFalse(Date date);
Before
关键字会将publicationDate
与您传递的date
作为参数进行比较,因此无需说BeforeDate
。就像Spring Data documentation中的一个例子:
Before
- &gt; findByStartDateBefore
生成以下SQL部分… where x.startDate < ?1