


User operation interception and logging - Custom annotations + AOP interception technology explanation
As an operator, in addition to dealing with system production problems, we also need to deal with a large number of user-reported events. This part of the work takes up a lot of manpower. Therefore, consider turning part of the event query processing into a self-service platform to allow users to check and process by themselves. So there is a user self-service system. Considering how to measure the specific realization value of this tool platform, user operation statistics are needed to provide credible data.
The above is the background of this article. The architecture of the self-service system is the traditional springmvc+spinrg+mybatis+oracle. The first thing that comes to mind when thinking of logging is AOP interception processing. There are many related technical posts online. Problems encountered in simple small projects can generally be solved by Du Niang~\(≧▽≦)/~
Custom annotation:
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD)public @interface LogAnnotation { String operateModelName() default ""; String operateFuncName() default ""; String operationType() default ""; String operateDescribe() default ""; }
in the controller Layer reference annotation
@Controller @RequestMapping(value="/kit")public class QueryClientInfoController { @Resourceprivate IClientService clientService; private Logger logger = Logger.getLogger(this.getClass().getName()); @RequestMapping(value="/queryClientRegInfo") @LogAnnotation(operateModelName="用户注册模块", operateFuncName="queryClientRegInfo", operationType="query", operateDescribe="查询客户注册信息")public void queryClientRegInfo(HttpServletRequest request,HttpServletResponse response){ String client_idno = request.getParameter("idno");Client client = clientService.queryClientRegInfo(client_idno);//调用service System.out.println("queryClientRegInfo:"+client.getName()); String jsonMap = JSON.toJSONString(client); response.setCharacterEncoding("UTF-8");try { response.getWriter().write(jsonMap); response.getWriter().flush(); response.getWriter().close(); } catch (IOException e) { e.printStackTrace(); } } }
The specific implementation code of other service layers related to querying user registration information will not be posted.
Implementation of interceptor
@Service(value="userLogService")public class UserLogServiceImpl implements IUserLogService { @Resourceprivate UserLogDao userLogDao; @Overridepublic void insert(UserLog record) {return userLogDao.insert(record); }@Overridepublic void logBusiController(JoinPoint joinPoint) { Map<String, Object> map = new HashMap<String, Object>(); String targetName = joinPoint.getTarget().getClass().getName(); String methodName = joinPoint.getSignature().getName(); Object[] arguments = joinPoint.getArgs(); Class targetClass;try { targetClass = Class.forName(targetName); Method[] methods = targetClass.getMethods();for (Method method : methods) {if(method.getName().equals(methodName)) { Class[] clazzs = method.getParameterTypes();if(clazzs.length == arguments.length ) {if(method.getAnnotation(LogAnnotation.class)!= null){ map.put("operateModelName", method.getAnnotation(LogAnnotation.class).operateModelName()); map.put("operateFuncName", method.getAnnotation(LogAnnotation.class).operateFuncName()); map.put("operationType", method.getAnnotation(LogAnnotation.class).operationType()); map.put("operateDescribe", method.getAnnotation(LogAnnotation.class).operateDescribe()); }elsebreak; } } } } catch (ClassNotFoundException e) { e.printStackTrace(); } HttpServletRequest request =((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); HttpSession session =request.getSession(); User user = (User) session.getAttribute("currentUser"); System.out.println("currentUser:"+user.getName()+"\n targetName:"+targetName+"\n methodName:"+methodName+"\n operateModelName:"+map.get("operateModelName")+"\n operateFuncName:"+map.get("operateFuncName")+"\n operationType:"+map.get("operationType")+"\n operateDescribe:"+map.get("operateDescribe"));} }
Next, you need to make interception settings in the configuration file:
Add ## to spring-mvc.xml
#<bean id="LogService" class="com.bbc_kit.common.service.impl.UserLogServiceImpl"></bean> <aop:config> <aop:pointcut id="logBusiControllerPoint" expression="execution(* com.bbc_kit.business.controller..*.*(..))" /> <aop:aspect id="logService" ref="LogService"> <aop:after pointcut-ref="logBusiControllerPoint" method="logBusiController"/> </aop:aspect> </aop:config>
currentUser:renhuang targetName:com.bbc_kit.business.controller.QueryClientInfoController methodName:queryClientRegInfo operateModelName:用户注册模块 operateFuncName:queryClientRegInfo operationType:query operateDescribe:查询客户注册信息
The above is the detailed content of User operation interception and logging - Custom annotations + AOP interception technology explanation. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



With the rapid development of social media, Xiaohongshu has become one of the most popular social platforms. Users can create a Xiaohongshu account to show their personal identity and communicate and interact with other users. If you need to find a user’s Xiaohongshu number, you can follow these simple steps. 1. How to use Xiaohongshu account to find users? 1. Open the Xiaohongshu APP, click the "Discover" button in the lower right corner, and then select the "Notes" option. 2. In the note list, find the note posted by the user you want to find. Click to enter the note details page. 3. On the note details page, click the "Follow" button below the user's avatar to enter the user's personal homepage. 4. In the upper right corner of the user's personal homepage, click the three-dot button and select "Personal Information"

In Ubuntu systems, the root user is usually disabled. To activate the root user, you can use the passwd command to set a password and then use the su- command to log in as root. The root user is a user with unrestricted system administrative rights. He has permissions to access and modify files, user management, software installation and removal, and system configuration changes. There are obvious differences between the root user and ordinary users. The root user has the highest authority and broader control rights in the system. The root user can execute important system commands and edit system files, which ordinary users cannot do. In this guide, I'll explore the Ubuntu root user, how to log in as root, and how it differs from a normal user. Notice

PyCharm is a very popular Python integrated development environment (IDE). It provides a wealth of functions and tools to make Python development more efficient and convenient. This article will introduce you to the basic operation methods of PyCharm and provide specific code examples to help readers quickly get started and become proficient in operating the tool. 1. Download and install PyCharm First, we need to go to the PyCharm official website (https://www.jetbrains.com/pyc

LinuxDeploy operating steps and precautions LinuxDeploy is a powerful tool that can help users quickly deploy various Linux distributions on Android devices, allowing users to experience a complete Linux system on their mobile devices. This article will introduce the operating steps and precautions of LinuxDeploy in detail, and provide specific code examples to help readers better use this tool. Operation steps: Install LinuxDeploy: First, install

Analysis of user password storage mechanism in Linux system In Linux system, the storage of user password is one of the very important security mechanisms. This article will analyze the storage mechanism of user passwords in Linux systems, including the encrypted storage of passwords, the password verification process, and how to securely manage user passwords. At the same time, specific code examples will be used to demonstrate the actual operation process of password storage. 1. Encrypted storage of passwords In Linux systems, user passwords are not stored in the system in plain text, but are encrypted and stored. L

Presumably many users have several unused computers at home, and they have completely forgotten the power-on password because they have not been used for a long time, so they would like to know what to do if they forget the password? Then let’s take a look together. What to do if you forget to press F2 for win10 boot password? 1. Press the power button of the computer, and then press F2 when turning on the computer (different computer brands have different buttons to enter the BIOS). 2. In the bios interface, find the security option (the location may be different for different brands of computers). Usually in the settings menu at the top. 3. Then find the SupervisorPassword option and click it. 4. At this time, the user can see his password, and at the same time find the Enabled next to it and switch it to Dis.

With the popularity of smartphones, the screenshot function has become one of the essential skills for daily use of mobile phones. As one of Huawei's flagship mobile phones, Huawei Mate60Pro's screenshot function has naturally attracted much attention from users. Today, we will share the screenshot operation steps of Huawei Mate60Pro mobile phone, so that everyone can take screenshots more conveniently. First of all, Huawei Mate60Pro mobile phone provides a variety of screenshot methods, and you can choose the method that suits you according to your personal habits. The following is a detailed introduction to several commonly used interceptions:

In Linux systems, you can use the following command to view the contents of the log file: tail command: The tail command is used to display the content at the end of the log file. It is a common command to view the latest log information. tail [option] [file name] Commonly used options include: -n: Specify the number of lines to be displayed, the default is 10 lines. -f: Monitor the file content in real time and automatically display the new content when the file is updated. Example: tail-n20logfile.txt#Display the last 20 lines of the logfile.txt file tail-flogfile.txt#Monitor the updated content of the logfile.txt file in real time head command: The head command is used to display the beginning of the log file
