日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

spring --aop(日志记录)在工程中实际使用

發布時間:2023/11/29 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring --aop(日志记录)在工程中实际使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

###1.日志切面

package com.readygo.zbhealth.common;import java.util.Arrays; import java.util.List;import org.aspectj.lang.ProceedingJoinPoint;public class LoggingAspect {public Object Around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable{Object result = null;String methodName = proceedingJoinPoint.getSignature().getName();try {System.out.println("請求路徑:/"+methodName+",請求參數:");List<Object> list = Arrays.asList(proceedingJoinPoint.getArgs());switch (methodName) {case "getSpecialist":System.out.println("searcheContent:"+list.get(0)+"\n"+"pageNum:"+list.get(1)+"\n"+"lastTime:"+list.get(2)+"\n"+"typeId:"+list.get(3)+"\n");break;case "getQuestionDetail":System.out.println("questionId:"+list.get(0)+"\n"+"userId:"+list.get(1)+"\n");break;case "getSpecialistDetail":System.out.println("specialistId:"+list.get(0)+"\n"+"userId:"+list.get(1)+"\n");break; case "getQuestionList":System.out.println("userId:"+list.get(0)+"\n"+"flag:"+list.get(1)+"\n");break;default:break;}result = proceedingJoinPoint.proceed();} catch (Exception e) {System.out.println("請檢查參數個數");e.printStackTrace();}return result;}}

###2.xml配置文件

<bean id="loggingAspect" class="com.readygo.zbhealth.common.LoggingAspect"></bean><aop:config><aop:pointcut expression="execution(* com.readygo.zbhealth.controller.ThirdPartController.*(..))" id="aopPointcut"/><aop:aspect ref="loggingAspect"><aop:around method="Around" pointcut-ref="aopPointcut"/></aop:aspect></aop:config>

###3.controller文件

@RestController public class ThirdPartController {@Autowiredprivate ThirdPartService thirdPartService;/*** 獲取專家列表* @param searcheContent* @param pageNum* @param lastTime* @param typeId* @return 專家列表*/@RequestMapping(value = "/getSpecialist", method=RequestMethod.POST)public ResultObject getSpecialist(@RequestParam("searcheContent") String searcheContent,@RequestParam("pageNum") String pageNum,@RequestParam("lastTime") String lastTime,@RequestParam("typeId") String typeId){ResultObject resultObject = new ResultObject();try {resultObject = thirdPartService.getSpecialist(searcheContent, pageNum, lastTime, typeId);} catch (Exception e) {resultObject = Utils.resultCatchInfo(new Object());e.printStackTrace();}return resultObject;} }

###4.驗證結果

請求路徑:/getSpecialist,請求參數: searcheContent:搜索內容 pageNum:1 lastTime:20160914112200 typeId:1000000000

###5.功能
該日志切面配置在controller層中的每個方法上,功能是打印出 請求路徑 與 請求參數。

轉載于:https://my.oschina.net/u/2312022/blog/746656

總結

以上是生活随笔為你收集整理的spring --aop(日志记录)在工程中实际使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。