1.建立存储用户登录日志表
create table `log`(
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) DEFAULT NULL,
`userIP` varchar(255) DEFAULT NULL,
`actionClassName` varchar(6000) DEFAULT NULL,
`actionDate` varchar(255) DEFAULT NULL,
`result` varchar(6000) DEFAULT NULL,
PRIMARY KEY(`id`)
)ENGINE=InnoDB AUTO_INCREMENT =1 DEFAULT CHARSET = utf8;
2.添加maven依赖
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.1</version>
</dependency>
<!-- 使用数据源 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.14</version>
</dependency>
3.配置拦截器Filter
package com.hly.sirius.filter;
/**
* @author :hly
* @github :github.com/SiriusHly
* @blog :blog.csdn.net/Sirius_hly
* @date :2018/10/2
*/
@WebFilter(filterName = "VisitorFilter",urlPatterns = "/index")
public class VisitorFilter