【问题标题】:please help me with writing following spring data jpa请帮我写下spring data jpa
【发布时间】:2015-07-13 13:47:33
【问题描述】:

我想写这样的东西:

find where player id = ?1 && (lastspinneddate < ?2 || lastspinneddate == null)

,但是当我这样写的时候:

repo.findByPlayerIdAndLastSpinnedDateBeforeOrLastSpinnedDateIsNull(playerId,startOfDay);

,但是这样返回是不正确的:

find where (player id = ?1 && lastspinneddate < ?2) || lastspinneddate == null

请帮我写上面的spring data jpa,提前谢谢

【问题讨论】:

  • 您查看过 QueryDSL 或 Specification API 吗?

标签: spring spring-boot spring-data spring-data-jpa


【解决方案1】:

只需用类似的东西注释方法

@Query("select p from Player p where p.id = ?1 && (p.lastSpinnedDate < ?2 or p.lastSpinnedDate is null)")

【讨论】:

  • 感谢您的回复,但我们不能不写@Query,我想知道spring data jpa有多强大和灵活?
  • 自动查询生成适用于非常简单的情况。它不应该避免尽可能多的手工查询。该方法的可怕名称本身就表明您应该指定一个查询。
  • 如何在@Query 中检查 null,它的意思是意外令牌“null”
  • 我的查询遗漏了一个结束括号。我修好了它。我不知道这是否是您的查询的问题。发布它,并发布完整的异常堆栈跟踪。
猜你喜欢
  • 2017-07-17
  • 1970-01-01
  • 2017-11-29
  • 2017-05-10
  • 1970-01-01
  • 2020-06-16
  • 2020-01-27
  • 2019-05-17
  • 1970-01-01
相关资源
最近更新 更多