一、准备操作
熟悉IDEA 和Spring环境编程;
熟悉spring或者spring boot基于MVC的编程;
查看并运行例子: spring-boot-sample-aop.zip
安装mysql数据库 https://www.mysql.com/
二、实验内容
构建一个用户记录的切面。要求:
a. 对于所有的登录操作,记录各各次登录的时间、用户,存入UserLog表格中。
b. 对于所有的登出操作,记录各各次登录的时间、用户,存入UserLog表格中。
c. 对于用户新的输入操作,记录其表单值,存入InsertLog表格中。
三、实验过程
3.1项目结构
项目结构.png
项目结构.png
3.2配置数据库连接
数据库连接.png
3.3实现Userlog表的插入(Insertlog表类似)
userlog的插入.png
3.4定义实体类Insertlog与Userlog
实体类.png
3.5定义userlog接口,实现对登陆登出操作的记录(type表示本次操作的类型为登入或者登出)
Userlog接口.png
3.6接口实现类
AdminDao.png
3.7切面类的实现
3.7.1登陆时记录登陆时间以及用户并存入Userlog表中,操作类型为login
Loginin.png
3.7.2登出时记录登陆时间以及用户并存入Userlog表中,操作类型为logout
logout.png
3.7.3对于用户的输入操作,记录alumni的id,操作时间以及用户
insertlog.png
3.8测试类
测试类.png
3.9实验结果
实验截图.png
数据库截图
数据库截图(Userlog).png
数据库截图(Insertlog).png
数据库截图(Alumni).png