问题描述
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);