添加大量访问日志记录

This commit is contained in:
2018-04-26 13:04:58 +08:00
parent 9ef0093b50
commit 8011ce135e
12 changed files with 199 additions and 19 deletions

View File

@@ -1,6 +1,11 @@
package com.fjy.spring.controller;
import com.fjy.spring.domain.TbLog;
import com.fjy.spring.domain.TbUser;
import com.fjy.spring.service.LogService;
import com.fjy.spring.untils.GetIPAddrUtil;
import com.fjy.spring.untils.LogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
@@ -10,6 +15,9 @@ import org.springframework.web.bind.support.SessionStatus;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import static com.fjy.spring.constant.GlobalConstant.USER_SESSION_KEY;
@Controller
@@ -18,70 +26,108 @@ public class NavController {
@Resource
HttpServletRequest request;
@Autowired
private LogService logService;
@GetMapping(value = {"index",""})
public String toLoginPage(){
//获取访问头信息
addIndexLog(request.getHeader("user-agent"));
return "login";
}
@GetMapping(value = {"testthymeleaf"})
public String toTestPage(){
addVisitLog("测试页面 testthymeleaf");
return "/dist/thymeleafTest";
}
@GetMapping(value = {"axiosTest"})
public String toTestAxiosPage(){
addVisitLog("测试页面 axiosTest");
return "/dist/axiosTest";
}
@GetMapping(value = {"/home"})
public String toHomePage(){
addVisitLog("首页 home");
return "home/home";
}
@GetMapping(value = {"/logout"})
public String toLogOut(SessionStatus status){
//request.getSession().getAttribute(USER_SESSION_KEY).invalidate();
addVisitLog("登出 logout");
status.setComplete();
return "login";
}
@GetMapping(value = {"/home/feedback"})
public String toFeedbackPage(){
addVisitLog("反馈页面 /home/feedback");
return "home/feedback";
}
@GetMapping(value = {"/home/about"})
public String toAboutPage(){
addVisitLog("关于页面 /home/about");
return "home/about";
}
@GetMapping(value = {"/home/admin"})
public String toAdminPage(){
addVisitLog("管理员页面 /home/admin");
return "home/admin";
}
@GetMapping(value = {"/home/admin/managecourse"})
public String toManageCoursePage(){
addVisitLog("课程管理页面 /home/admin/managecourse");
return "home/managecourse";
}
@GetMapping(value = {"/home/admin/manageuser"})
public String toManageUserPage(){
addVisitLog("用户管理页面 /home/admin/manageuser");
return "home/manageuser";
}
@GetMapping(value = {"/home/admin/homework"})
public String toHomeworkPage(){
addVisitLog("作业管理页面 /home/admin/homework");
return "home/homework";
}
@GetMapping(value = {"/home/user"})
public String toUserPage(){
addVisitLog("个人中心页面 /home/user");
return "home/user";
}
@GetMapping(value = {"/error"})
public String toErrorPage(){
addVisitLog("404页面 error");
return "error";
}
/**
* 首页的访问日志记录
* @param content
*/
private void addIndexLog(String content){
TbUser user = new TbUser();
user.setColname("访客");
TbLog log = LogUtil.addLog(user,content,request);
logService.addLogRec(log);
}
/**
* 登陆后的访问日志记录
* @param content
*/
private void addVisitLog(String content){
TbUser user =(TbUser)request.getSession().getAttribute(USER_SESSION_KEY);
TbLog log = LogUtil.addLog(user,content,request);
logService.addLogRec(log);
}
}