首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >弹簧数据JPA法

弹簧数据JPA法
EN

Stack Overflow用户
提问于 2020-08-29 16:47:48
回答 2查看 67关注 0票数 0

我有办法

代码语言:javascript
复制
List<Notification> findTop20ByToUserIdAndIdGreaterThanAndOrderByIdDesc(Long ToUserId, Long lastId);

我有通知列表,使用此方法我想:

  1. 选择发送到"toUserId"

的通知

  1. 选择最后20个添加了

  1. 按Desc

对20进行排序

  1. 并选择大于(我提供给方法的lastId数(因为更新原因)的方法)。

这不起作用,并抛出异常:

代码语言:javascript
复制
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.
代码语言:javascript
复制
 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;
}

我怎样才能重写适当的工作方法呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-08-30 00:35:12

看起来问题就像在方法名称中应该添加实体类名:通知--这个方法是工作的:

代码语言:javascript
复制
List<Notification> findTop20NotificationByToUserIdAndIdGreaterThanOrderByIdDesc(Long ToUserId, Long lastId);
票数 0
EN

Stack Overflow用户

发布于 2020-08-30 04:22:55

方法名称不符合标准。您可以尝试使用下面的方法名。

代码语言:javascript
复制
List<Notification> findTop20NoByToUserIdIsAndIdIsGreaterThanOrderByIdDesc(Long ToUserId, Long lastId);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63649499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档