如何在jasper中使用日期范围类型参数作为普通的java.util.date
我创建了两个输入控制器BeginDate和EndDate作为日期范围类型。我需要将作为日期范围输入的日期转换为util.date。这些是我创建的数据类型。
I have created two input controllers BeginDate and EndDate as date range type. I need to convert that dates which are input as date range to util.date.These are data types I have created.
<parameter name="BeginDate" class="net.sf.jasperreports.types.date.DateRange"/>
<parameter name="EndDate" class="net.sf.jasperreports.types.date.DateRange"/>
<![CDATA[SELECT *
FROM table
WHERE $X{BETWEEN,date,BeginDate,EndDate}
AND total > 0;]]>
我需要在下面使用这些日期。
I need to use that dates in below.
<![CDATA[SELECT *
FROM table
WHERE
date >= $P{BeginDate} AND
date < $P{EndDate}
AND total > 0;]]>
DateRange
type提供了2种方法: getStart()
和 getEnd()
获取的开始和结束范围。这些方法返回 java.util.Date
可以进一步使用的对象。
The DateRange
type provides 2 methods: getStart()
and getEnd()
to get the beginning and end of the range. These methods return java.util.Date
objects which you could use further.
但是因为 DateRange
在查询表达式中不允许输入类型 java.util.Date
的新参数,以便根据需要使用:
But because the DateRange
type is not allowed in the query expression you need to create new parameters of type java.util.Date
to use as you want:
<parameter name="BeginDate_start" class="java.util.Date">
<defaultValueExpression><![CDATA[$P{BeginDate}.getStart()]]></defaultValueExpression>
</parameter>
<parameter name="EndDate_end" class="java.util.Date">
<defaultValueExpression><![CDATA[$P{EndDate}.getEnd()]]></defaultValueExpression>
</parameter>
然后您的查询可能如下所示:
Then your query may look like so:
<queryString>
<![CDATA[SELECT * FROM table
WHERE date >= $P{BeginDate_start} AND date < $P{EndDate_end} AND total > 0]]>
</queryString>