当前位置:网站首页>使用切面实现记录操作日志
使用切面实现记录操作日志
2022-07-06 21:08:00 【&友情岁月&】
@Aspect @Component public class SysLogAspect { @Autowired private SysLogService sysLogService; /** * 切点 */ @Pointcut("@annotation(com.platform.annotation.SysLog)") public void logPointCut() { } /** * 前置通知 * * @param joinPoint 连接点 */ @Before("logPointCut()") public void saveSysLog(JoinPoint joinPoint) { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); SysLogEntity sysLog = new SysLogEntity(); SysLog syslog = method.getAnnotation(SysLog.class); if (syslog != null) { //注解上的描述 sysLog.setOperation(syslog.value()); } //请求的方法名 String className = joinPoint.getTarget().getClass().getName(); String methodName = signature.getName(); sysLog.setMethod(className + "." + methodName + "()"); //请求的参数 Object[] args = joinPoint.getArgs(); String params = JSON.toJSONString(args[0]); sysLog.setParams(params); //获取request HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); //设置IP地址 sysLog.setIp(IPUtils.getIpAddr(request)); //用户名 SysUserEntity sysUserEntity = ShiroUtils.getUserEntity(); String username = ""; if ("login".equals(methodName)) { username = params; } if (null != sysUserEntity) { username = ShiroUtils.getUserEntity().getUsername(); } sysLog.setUsername(username); sysLog.setCreateDate(new Date()); //保存系统日志 sysLogService.save(sysLog); } }
@Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface SysLog { String value() default "操作日志"; }
@SysLog("删除菜单") @RequestMapping("/delete") @RequiresPermissions("sys:menu:delete") public R delete(@RequestBody Long[] menuIds) { for (Long menuId : menuIds) { if (menuId.longValue() <= 30) { return R.error("系统菜单,不能删除"); } } sysMenuService.deleteBatch(menuIds); return R.ok(); }
边栏推荐
- Clock in during winter vacation
- AVL树插入操作与验证操作的简单实现
- QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式
- Open3D 网格滤波
- Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
- Construction of Hisilicon universal platform: color space conversion YUV2RGB
- Index of MySQL
- Termux set up the computer to connect to the mobile phone. (knock the command quickly), mobile phone termux port 8022
- Can the applet run in its own app and realize live broadcast and connection?
- Force buckle ----- path sum III
猜你喜欢
接口数据安全保证的10种方式
QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
Mobile measurement and depth link platform - Branch
[security attack and Defense] how much do you know about serialization and deserialization?
【DPDK】dpdk样例源码解析之三:dpdk-l3fwd_001
[safe office and productivity application] Shanghai daoning provides you with onlyoffice download, trial and tutorial
22.(arcgis api for js篇)arcgis api for js圆采集(SketchViewModel)
1200.Minimum Absolute Difference
[leetcode] 700 and 701 (search and insert of binary search tree)
21. (article ArcGIS API for JS) ArcGIS API for JS rectangular acquisition (sketchviewmodel)
随机推荐
VHDL implementation of single cycle CPU design
Calculation of time and space complexity (notes of runners)
我的勇敢对线之路--详细阐述,浏览器输入URL发生了什么
PHP lightweight Movie Video Search Player source code
[development software] tilipa Developer Software
机器学习笔记 - 使用机器学习进行鸟类物种分类
QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
A 股指数成分数据 API 数据接口
[dpdk] dpdk sample source code analysis III: dpdk-l3fwd_ 001
如何检测mysql代码运行是否出现死锁+binlog查看
数据的存储
Kbone与小程序跨端开发的一些思考
Que savez - vous de la sérialisation et de l'anti - séquence?
【安全攻防】序列化與反序列,你了解多少?
MySQL的索引
小程序能运行在自有App中,且实现直播和连麦?
二进制、八进制、十六进制
Graphical tools package yolov5 and generate executable files exe
[hcie TAC] question 3
[security attack and Defense] how much do you know about serialization and deserialization?