<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ## 系統日志 利用`spring`框架中`aop`,我們可以實現業務代碼與系統級服務進行解耦,例如日志記錄、事務及其他安全業務等,可以使得我們的工程更加容易維護、優雅。如何在系統中添加相應的日志呢? ##### 添加依賴 ``` <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> ``` ##### 自定義注解 ```java @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface SysLog { String value() default ""; } ``` ##### 配置切面 ```java @Aspect @Component public class SysLogAspect { @Autowired private SysLogService sysLogService; private static Logger logger = LoggerFactory.getLogger(SysLogAspect.class); @Around("@annotation(sysLog)") public Object around(ProceedingJoinPoint joinPoint,com.yami.shop.common.annotation.SysLog sysLog) throws Throwable { long beginTime = SystemClock.now(); //執行方法 Object result = joinPoint.proceed(); //執行時長(毫秒) long time = SystemClock.now() - beginTime; SysLog sysLogEntity = new SysLog(); if(sysLog != null){ //注解上的描述 sysLogEntity.setOperation(sysLog.value()); } //請求的方法名 String className = joinPoint.getTarget().getClass().getName(); String methodName = joinPoint.getSignature().getName(); sysLogEntity.setMethod(className + "." + methodName + "()"); //請求的參數 Object[] args = joinPoint.getArgs(); String params = Json.toJsonString(args[0]); sysLogEntity.setParams(params); //設置IP地址 sysLogEntity.setIp(IPHelper.getIpAddr()); //用戶名 String username = SecurityUtils.getSysUser().getUsername(); sysLogEntity.setUsername(username); sysLogEntity.setTime(time); sysLogEntity.setCreateDate(new Date()); //保存系統日志 sysLogService.save(sysLogEntity); return result; } } ``` 將自定義的注解作為切入點,參數是`ProceedingJoinPoint`和`sysLog`,`ProceedingJoinPoint`用來獲取當前執行的方法,`syslog`用來獲取注解里面的值。 #### 在需要記錄日志的方法上,添加注解`@SysLog(value)` ```java @SysLog("修改角色") @PutMapping @PreAuthorize("@pms.hasPermission('sys:role:update')") public ResponseEntity<Void> update(@RequestBody SysRole role){ sysRoleService.updateRoleAndRoleMenu(role); return ResponseEntity.ok().build(); } ``` 當操作這個方法時,將會被記錄到數據庫中,在日志管理中能看到相應操作的內容。 ![img](https://box.kancloud.cn/4ff625398e31974b7de6fe9e06c2b847_1373x202.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看