<!-- 指定日期活动被创建次数查询结果数据集-->
<resultMap id="countPlayTimesMap" type="HashMap">
<result property="gid" column="gid"/>
<result property="count" column="count" javaType="Integer"/>
</resultMap>
<!-- 按指定日期获取游戏被用来创建活动的次数 -->
<select id="countActivityCreateTimesByDayAndGids" resultMap="countPlayTimesMap" parameterType="map">
SELECT gid, count(id) AS count FROM activity WHERE gid IN
<foreach collection="gids" item="item" index="index" open="("
separator="," close=")">
#{item}
</foreach>
AND DATE( FROM_UNIXTIME(create_time / 1000)) = DATE( FROM_UNIXTIME(#{dayTime} / 1000)) GROUP BY gid
</select>
在dao层中的java代码
List<Map<String, Object>> countActivityCreateTimesByDayAndGids(@Param("gids") List<String> gids, @Param("dayTime") long dayTime);
在service层中的java代码
@Override
public List<Map<String, Integer>> countActivityCreateTimesByDayAndGids(List<String> ids, long dayTime) throws TException {
List<Map<String, Integer>> list = new ArrayList<>();
if (ids == null || ids.size() <= 0) {
return null;
}
List<Map<String, Object>> res = mapper.countActivityCreateTimesByDayAndGids(ids, dayTime);
if (res != null && res.size() > 0) {
for (int i = 0; i < res.size(); i++) {
Map<String, Object> map = res.get(i);
Map<String, Integer> m = new HashMap<>();
m.put("gid", (Integer) map.get("gid"));
Integer count = (Integer) map.get("count");
m.put("count", count == null ? 0 : count);
list.add(m);
}
return list;
}
return null;
}
控制层中的java代码
List<Map<String, Integer>> activityCounts = activityService.countActivityCreateTimesByDayAndGids(ids, dt.getTime());
model.addAttribute("activityCounts", activityCounts);
js中
<div class="cont">
<div class="pic">
<img src="${config.url}${game.avatar}" alt="" style="width:128px;height:128px;" />
</div>
<dl class="info">
<dt style="min-width:480px;">游戏名:${game.name}</dt>
<!-- <dd>分类:${game.type.name}</dd> -->
<dd>当天被玩次数:${res.count}</dd>
<dd>当天被用于创建活动次数:
<#assign actc=0/>
<#list activityCounts as ac>
<#if ac.gid==game.id>
<#assign actc=ac.count/>
</#if>
</#list>
${actc}
</dd>
</dl>
</div>
freemarker中的<#assign>标签
<#assign x>
<#list ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"] as n>
${n}
</#list>
</#assign>
${x} ${x}能显示所有规定域内的文本内容