Freemarker - 查询地图(Freemarker - querying a Map)
在Freemarker中,我有一个
Map<Long, ...>
(键是Long
)。Freemarker的
map[key]
仅支持字符串键。 所以我尝试过map?api.get(0)
但表现得像值不存在。 但如果我这样做<#list statsForThisBox as projID, val> Project #${projID?c} has value: <b>${val???c}</b> </#list>
然后我看到条目在那里。
项目#64256具有值:true项目#0具有值:true
有没有办法查询
Map
的Long
键? (除了在Java中创建特殊函数。)编辑:我在想类似的东西
map?api.get("java.util.Long"?new(123))
In Freemarker, I have a
Map<Long, ...>
(the keys areLong
).Freemarker's
map[key]
only supports string keys. So I have triedmap?api.get(0)
but that behaves like the value is not there. Yet if I do<#list statsForThisBox as projID, val> Project #${projID?c} has value: <b>${val???c}</b> </#list>
Then I see that the entries are there.
Project #64256 has value: true Project #0 has value: true
Is there a way to query a
Map
for aLong
key? (Other than creating a special function in Java.)Edit: I am thinking of something like
map?api.get("java.util.Long"?new(123))
原文:https://stackoverflow.com/questions/46574081
最满意答案
您正在从
Calendar
常数中减去而不是从该常数中减去该值。更改:
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH - 1), 1);
附:
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) - 1, 1);
解决方案更简单:
calendar.roll(Calendar.MONTH, false);
...将“滚”一个月“下”。
You are subtracting from a
Calendar
constant instead of subtracting from the value you get from that constant.Change:
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH - 1), 1);
With:
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) - 1, 1);
Easier solution:
calendar.roll(Calendar.MONTH, false);
... will "roll" one month "down".
相关问答
更多-
从今天开始减去当月的日期,即可获得上个月的最后一天: date_sub(now(), day(now()) 这包括当前时间。 要到午夜,您可以将其截断到月初并减去一天: date_sub(trunc(now(), 'month'), 1) 两者都会产生时间戳,但可以很容易地转换为字符串。 Subtract the day of month from today and you get the last day of the previous month: date_sub(now(), day(now( ...
-
GBQ上个月(GBQ previous month)[2022-02-10]
尝试 SELECT * FROM TABLE_QUERY([BI_UU_HH], "REGEXP_MATCH(table_id, 'CID_BKID_AID_Raw_' + REPLACE(LEFT(STRING(DATE_ADD(CURRENT_TIMESTAMP(), -1, 'MONTH')), 7), '-', ''))") 有关更多详细信息,请参见TABLE_QUERY 要么 稍微修改过的版本(仍然在Legacy SQL中)使用STRFTIME_UTC_USEC函数而不是字符串操作 SELECT ... -
DAX迄今为止的上个月总计为上个月的整个总数(DAX Previous Month to date total is giving entire previous month's entire total)[2022-07-29]
如果您在月份级别进行汇总(即您在查看2016年12月与2016年11月),那么您上面的测量将显示12月份的整个月份与11月份的整个月份相比较(自12月份以来一个月和十一月不是,它会导致你看到的不匹配)。 如果筛选到当前日期(例如12月7日),那么您的MTD和上个月MTD指标将仅显示您到相应月份的第7个月。 假设你不想过滤到一天的水平(不是不合理的),你可以增强你的公式来过滤未来的日期。 例如: PMYTD = totalmtd( sum(SALES_VOUCHERS[SaleValue]), ... -
SQL:从上个月的第二个工作日获取值(SQL: Get the value from the 2nd last business day of the previous month)[2023-04-23]
declare @table table (report_date datetime , currency varchar(3), country varchar(2), cash_balance int, cash_balance_last_month int) insert into @table values (cast('2016-05-03' as datetime), 'USD' , 'US' , 110 , NULL), (cast('2 ... -
需要查找上个月的最后一天以及上个月的前一天(Need to find last day of previous month and previous to previous month)[2023-02-11]
查找上个月最后一天的最简单方法是找到当月的第一天(始终有效),然后减去一天。 然后在上个月做同样的事情。 DateTime startOfMonth = new DateTime(today.Year, today.Month, 1); DateTime endOfPreviousMonth = startOfMonth.AddDays(-1); DateTime endOfPreviousPreviousMonth = startOfMonth.AddMonths(-1).AddDays(-1); Th ... -
减去两个日期并在其上调用to_i将为您提供天数差异,您可以打开它: if (Date.today - other_date).to_i < 30 # less than a month else # more than a month end 当然,这并不完全符合几个月,但对于我的用例,它通常已经足够好了。 另一种选择是: if date_to_check > Date.today.last_month # within the last month end 或者检查是否包含在上个月的日期范 ...
-
您正在从Calendar常数中减去而不是从该常数中减去该值。 更改: calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH - 1), 1); 附: calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) - 1, 1); 解决方案更简单: calendar.roll(Calendar.MONTH, false); ...将“滚”一 ...
-
你可以使用eomonth()比较几个月: select t.* from t where ( day(data) >= 20 and eomonth(data) = eomonth(dateadd(month, -1, getdate())) ) or ( day(data) < 20 and eomonth(data) = emonth(getdate()) ); 你可以在SQL Server 2008中做到这一点,但日期算术有点麻烦。 一种方法是减去21天,并检查它是否是上个月: sele ...
-
当我运行查询 SELECT SUM(amount) AS people, DATE_FORMAT(NOW() - INTERVAL 1 MONTH, '%Y-%m-01') as from_date, DATE_FORMAT(NOW() ,'%Y-%m-01') as to_date FROM room WHERE userid = 1 AND date >= DATE_FORMAT(NOW() - INTERVAL 1 MONTH, '%Y-%m-01') AND date ...
-
而不是仅提供月份和年份提供实际日期,然后您可以获得您想要的结果 SET @month := 09; SET @year := 2014; SELECT sum(amount)FROM tester WHERE month(date_amount)= @month-1 AND day(date_amount) = day(last_day(date_amount)) 或者,您可以使用STR_TO_DATE首先转换给定日期的月份和年份,然后使用它而不是@Date Instead of just provi ...