免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1 首先引入jar包 spring.jar aopalliance.jar aspectjrt.jar aspectjtools.jar aspectjweaver.jar cglib-nodep-2.1_3.jar cglib-src-2.2.jar 这些个jar包不一定都用得上,但离配置到现在整理已经比较久了 有点忘了.2 spring 配置文件头 3 定义 aop拦截 4 处理拦截的类logMonitorAspectpublic class LogMonitor /* * 保存变量的ThreadLocal,保持在同一线程中同步数据. */private static final ThreadLocal SESSION_MAP = new ThreadLocal();private IUserLogInfoService userLogInfoService;public IUserLogInfoService getUserLogInfoService() return userLogInfoService;public void setUserLogInfoService(IUserLogInfoService userLogInfoService) this.userLogInfoService = userLogInfoService;/* * 获得线程中保存的属性. * * param attribute * 属性名称 * return 属性值 */public static Object get(String attribute) Map map = (Map) SESSION_MAP.get();return map.get(attribute);/* * 记录日志信息 * param joinpoint * throws Exception * throws IllegalAccessException */public void writeLogInfo(JoinPoint joinpoint) throws Exception, IllegalAccessException UserInfoVO sysUse = (UserInfoVO) UserSession.get(Contents.SESSION_USER_KEY);/ 在基类action中 设用户信息/UserSession.set(Contents.SESSION_USER_KEY, userVO);/UserSession.set(Contents.SESSION_USER_IP, request.getRemoteAddr();String userIP = (String) UserSession.get(Contents.SESSION_USER_IP);String temp = joinpoint.getStaticPart().toShortString();/ 获得操作类String classType = joinpoint.getTarget().getClass().getName();/ 获得方法名称String methodName = temp.substring(10, temp.length() - 1);Class className = Class.forName(classType);/ 获得方法的参数类型数组Object a = joinpoint.getArgs();Class o = new Classa.length;/ for (int i = 0; i a.length; i+) oi = ai.getClass();Method method = className.getMethod(methodName, o);LogDesc desc = method.getAnnotation(LogDesc.class);/ 获得方法的操作动作类型说明String actionDesc = ;if (desc != null) actionDesc = desc.actionDesc();/ 记录日志信息UserLogInfo userLogInfo = new UserLogInfo();if (sysUse != null) userLogInfo.setUserID(sysUse.getUserID();userLogInfo.setUserIp(userIP);userLogInfo.setOperateClass(classType);userLogInfo.setOperateMethod(methodName);/设置为一般日志信息标识位userLogInfo.setEnableFlag(C);userLogInfo.setOperateDescribe(actionDesc);userLogInfoService.addUserLog(userLogInfo);5 定义取得拦截方法描述的类 Retention(RetentionPolicy.RUNTIME)Target(ElementType.METHOD)public interface LogDesc String actionDesc();6 在每个需要拦截的方法头加上/* * 注册新用户 * * roseuid 3C30BD930399 */LogDesc(actionDesc = 新建会员)public MemberVO createMember(MemberVO memberVO) throws SysComException return memberRegisterDao.createMember(memberVO);7 设置、取得用户信息public class UserSession/private static ThreadLocal threadLocal = new ThreadLocal(); /public HttpServletRequest getContext() /return (HttpServletRequest)threadLocal.get(); / /public void setContext(HttpServletRequest request) /threadLocal.set(request); / /public void cleanContext() /threadLocal.set(null); / /* * 保存变量的ThreadLocal,保持在同一线程中同步数据. */ private static final ThreadLocal SESSION_MAP = new ThreadLocal(); /* * 工具类的protected构造方法. */ protected UserSession() /* * 获得线程中保存的属性. * * param attribute * 属性名称 * return 属性值 */ public static Object get(String attribute) Map map = (Map) SESSION_MAP.get(); /System.out.println(map.toString(); / System.out.println(map.containsKey(usersession); return map.get(attribute); /* * 获得线程中保存的属性,使用指定类型进行转型. * * param attribute * 属性名称 * param clazz * 类型 * param * 自动转型 * return 属性值 */ public static T get(String attribute, Class clazz) return (T) get(attribute); /* * 设置制定属性名的值. * * param attribute * 属性名称 * param value * 属性值 */ public static void set(String attribute, Obj
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年电梯安全评估报告
- 装配式建筑施工管理关键点分析
- 施工方案文件编写规范指引
- 车辆驾驶人安全培训手册
- 施工招标投标情况确认书及中标通知书
- 上下班打卡制度
- 2026年兰州资源环境职业技术大学单招职业适应性考试题库含答案详解(满分必刷)
- 2026年内蒙古乌兰察布盟单招职业倾向性测试题库及完整答案详解
- 2026年保定理工学院单招职业倾向性测试题库带答案详解(巩固)
- 2026年内蒙古通辽市单招职业适应性测试题库附答案详解(培优a卷)
- 2026春统编版二年级下册道德与法治教学设计(附目录)
- 2026年-(教科版2026新教材)科学一年级下册全册教学设计-新版
- 2026届云南省普通高中学业水平选择性考试调研测试政治试题
- 2026年就业市场:挑战与机遇并存高校毕业生就业指导与策略
- 2026中国科学院机关招聘应届毕业生5人笔试备考试题及答案解析
- 多囊卵巢综合征中西医结合诊疗指南(2025年版)
- 电梯安装安全培训讲议课件
- 2026年济南工程职业技术学院单招综合素质笔试模拟试题带答案解析
- 桌面盆栽行业分析报告
- 森林防火物资储备库建设标准
- 无人机救援方案
评论
0/150
提交评论