如何解决Spring Data JPA方法
List<Notification> findTop20ByToUserIdAndIdGreaterThanAndOrderByIdDesc(Long ToUserId,Long lastId);
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'notificationRepo': factorybean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.bagenger.persistence.dao.NotificationRepo.findTop20ByToUserIdAndIdGreaterThanAndOrderByIdDesc(java.lang.Long)! No property greaterThanAnd found for type Long! Traversed path: Notification.id.
My Entity:
@Entity
@Data
public class Notification {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
@Column(name = "id",unique = true,nullable = false)
private Long id;
private Long fromUserId;
private Long toUserId;
private String url;
@ColumnDefault("false")
private boolean isRead;
private String message;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
private LocalDateTime createDate;
}
我该如何重写方法才能正常工作?
解决方法
好像是方法名称出现问题,应添加实体类名称:通知 这个正在工作:
List<Notification> findTop20NotificationByToUserIdAndIdGreaterThanOrderByIdDesc(Long ToUserId,Long lastId);
,
方法名称不符合标准。您可以尝试使用以下方法名称。
List<Notification> findTop20NoByToUserIdIsAndIdIsGreaterThanOrderByIdDesc(Long ToUserId,Long lastId);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。