【发布时间】:2019-01-24 02:22:03
【问题描述】:
我的项目中有一个要求,需要将日期过滤器应用于管道分隔的字段。
如何使用最佳 Criteria API 来实现相同目标?
Table: Flyout
-------------------------------------------------------------
Name Date_flyout
-------------------------------------------------------------
John |08-06-2017|09-07-2017|02-10-2018|
Adam |06-06-2017|10-07-2017|03-06-2018|
Mary |07-08-2017|10-06-2017|06-06-2018|
-------------------------------------------------------------
Filter
From-Flyout-Date: 06-01-2017
To-Flyout-Date : 07-10-2017
Excepted ResultSet
-------------------------------------------------------------
Name Date_flyout
--------------------------------------------------------------
Adam |**06-06-2017**|10-07-2017|03-06-2018|
Mary |**07-08-2017**|10-06-2017|06-06-2018|
--------------------------------------------------------------
For obvious reason, the below criteria api wont work. However, how best we can modify the below to get excepted results??
criteria.add(Restrictions.ge("Date_flyout", "06-01-2017"))
criteria.add(Restrictions.le("Date_flyout", "07-10-2017"))
【问题讨论】:
-
为什么
Date_flyout有3个值? -
有一个
Restictions.between(),但ge() AND le()也应该可以工作... -
你的日期格式是什么??是“mm-dd-yyyy”吗??
标签: hibernate hibernate-criteria