日志统计
Posted 命
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了日志统计相关的知识,希望对你有一定的参考价值。
1.SQL语句-查询sys_user的id和username,页面传值,用<iframe>标签嵌入到统计页面
$(function() {
$("#btn2").click(function() {
var userid = $("#select").val();
if(userid != "") {
$("#iframe").attr("src","<%=basePath %>admin/demo/list_ii?userid="+userid)
}
});
});
<select id="select">
<option>请选择用户名</option>
<c:forEach items = "${list }" var = "i" varStatus="s">
<option value="${i.id }">${i.username }</option>
</c:forEach>
</select>
<input type="button" value="搜索" class="btn1" id="btn2"/>
</div>
<iframe id="iframe" frameborder="0" style="width: 700px;height: 600px;"></iframe>
2.SQL语句,统计日志
select count(body) as num,month(createtime) as month
from worklog
where userid = #{userid } and status = 1
group by month(createtime)
3.调用接口,创建map,将month=key,取值value=num
@RequestMapping(value="admin/demo/list_ii")
public String count_journal(int userid,Model model) {
//调用接口,获取数据
List<Map<String, Object>> list = journalService.count_body(userid);
//创建map
Map<Integer, Object> maps = new HashMap<>();
//遍历接口的list
for (Map<String, Object> map : list) {
//month=key,num=value,绑定到新创建的map上
maps.put((Integer) map.get("month"), map.get("num"));
}
model.addAttribute("map", maps);
return "admin/demo/list_ii";
}
4.页面传值-c 标签循环,三目运算判断
<c:forEach begin="1" end="12" varStatus="s">
<tr>
<td>${s.index}月</td>
<td>${map[s.index] eq null?0:map[s.index]}篇</td>
</tr>
</c:forEach>
以上是关于日志统计的主要内容,如果未能解决你的问题,请参考以下文章