I'm looking at the examples giving on this page (http://docs.spring.io/spring-data/jpa/docs/current/reference/html/jpa.repositories.html) about method naming, is it possible to create a complex chain method name such as

我正在查看关于方法命名的本页(http://docs.spring.io/spring-data/jpa/docs/current/reference/html/jpa.repositories.html)上给出的示例,是否可以创建一个复杂的链方法名称,如

findByProgrammeAndDirectorAndProgDateBetweenOrderByProgDateStartTimeAsc

In the example they give, they are only doing an OrderBy on one value. In the example above ProgDate and StartTime would be two separate values.

在他们给出的示例中,他们只在一个值上执行OrderBy。在上面的示例中,ProgDate和StartTime将是两个单独的值。

2 个解决方案

#1


76

The trick is to simply delimit the properties you want to sort by using the direction keywords Asc and Desc. So what you probably want in your query method is something like:

诀窍是使用方向关键字Asc和Desc简单地分隔要排序的属性。那么您在查询方法中可能需要的是:

…OrderByProgDateAscStartTimeAsc

Note, how we conclude the first property definition by Asc and keep going with the next property.

注意,我们如何通过Asc结束第一个属性定义并继续使用下一个属性。

Generally speaking, we recommend switching to @Query based queries, once method names exceed a certain length or complexity. The main reason being that it's awkward for clients to call these very long methods. With @Query you rather get the full power of the query language plus a reasonably sized method name that might be of higher level language to express the intent of the query.

一般来说,一旦方法名称超过一定的长度或复杂性,我们建议切换到基于@Query的查询。主要原因是客户称这些非常长的方法很尴尬。使用@Query,您可以获得查询语言的全部功能以及可能具有更高级语言的合理大小的方法名称来表达查询的意图。

更多相关文章

  1. Spring MVC-集成(Integration)-集成LOG4J示例(转载实践)
  2. Java提高篇——equals()方法和“==”运算符

随机推荐

  1. 解析PHP的基本文本输出
  2. 利用jQuery实现CheckBox全选/全不选/反选
  3. jquery中的globalEval()源码分析
  4. 从jQuery每个循环中删除item [i]
  5. Jquery 特效 图片轮转 菜单
  6. jQuery学习21---简单动画效果,show,hide,
  7. 将Object转换为字符串并返回[复制]
  8. Jquery 只执行一次的代码
  9. Jquery Validate 相关参数及常用的自定义
  10. BootStrap入门教程 (四)