1. 程式人生 > >聚富彩票源碼下載

聚富彩票源碼下載

源碼下載 clas tps util ntc ping around javax framework

聚富彩票源碼下載

地址一:【hubawl.com】
地址二:【bbscherry.com】

技術分享圖片

自定義註解

package com.xiaojukeji.common.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ ElementType.METHOD })@Retention(RetentionPolicy.RUNTIME)

br/>@Retention(RetentionPolicy.RUNTIME)
String value();
}

(1)@Target註解是標註這個類它可以標註的位置,常用的元素類型(ElementType):

public enum ElementType {
/* Class, interface (including annotation type), or enum declaration /
// TYPE類型可以聲明在類上或枚舉上或者是註解上
TYPE,

/** Field declaration (includes enum constants) */ 
// FIELD聲明在字段上 
FIELD, 

/** Method declaration */ 
// 聲明在方法上 
METHOD, 

/** Formal parameter declaration */ 
// 聲明在形參列表中 
PARAMETER, 

/** Constructor declaration */ 
// 聲明在構造方法上 
CONSTRUCTOR, 

/** Local variable declaration */ 
// 聲明在局部變量上 
LOCAL_VARIABLE, 

/** Annotation type declaration */ 
ANNOTATION_TYPE, 

/** Package declaration */ 
PACKAGE, 

/** * Type parameter declaration * * @since 1.8 */ 
TYPE_PARAMETER, 

/** * Use of a type * * @since 1.8 */ 
TYPE_USE

}

(2)@Retention註解表示的是本註解(標註這個註解的註解保留時期)

public enum RetentionPolicy {
/**

  • Annotations are to be discarded by the compiler.
    */
    // 源代碼時期
    SOURCE,

    /**

  • Annotations are to be recorded in the class file by the compiler
  • but need not be retained by the VM at run time. This is the default
  • behavior.
    */
    // 字節碼時期, 編譯之後

    CLASS,

    /**

  • Annotations are to be recorded in the class file by the compiler and
  • retained by the VM at run time, so they may be read reflectively.
  • @see java.lang.reflect.AnnotatedElement
    */
    // 運行時期, 也就是一直保留, 通常也都用這個
    RUNTIME
    }

(3)@Documented是否生成文檔的標註, 也就是生成接口文檔是, 是否生成註解文檔

二.AOP切面類---此處我用後置通知

package com.xiaojukeji.ecm.aop;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import nl.bitwalker.useragentutils.UserAgent;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.xiaojukeji.common.annotation.SystemLogAnnotation;
import com.xiaojukeji.dao.model.SystemLog;
import com.xiaojukeji.ep.ip.common.model.AdUser;
import com.xiaojukeji.ep.ip.common.utils.ContextHolder;
import com.xiaojukeji.service.ERPService;
import com.xiaojukeji.service.SystemLogService;
/**

  • <p>Description: [用戶操作日誌AOP]</p>
  • Created on 2017年11月24日 上午10:32:35
  • @author <a href="mailto: [email protected]">全冉</a>
  • @version 1.0
  • Copyright (c) 2017 全冉公司
    */
    @Component @Aspect
    br/>@Aspect
    public class EcmSysemLogAop {

    private static final Logger LOGGER = LoggerFactory.getLogger(EcmSysemLogAop.class);

    @Autowired
    private ERPService erpService;

    @Resource
    private SystemLogService systemLogService;

    /**

    • <p>Discription:[後置通知,掃描com.xiaojukeji包及此包下的所有帶有SystemLogAnnotation註解的方法]</p>
    • Created on 2017年11月24日 上午10:28:34
    • @param joinPoint 前置參數
    • @param systemLogAnnotation 自定義註解
    • @author:[全冉]
      /
      @After(("execution(
      com.xiaojukeji...(..)) && @annotation(systemLogAnnotation)"))
      public void doAfterAdvice(JoinPoint joinPoint, SystemLogAnnotation systemLogAnnotation) {
      LOGGER.info("=========================================用戶操作日誌-後置通知開始執行......=========================================");
      String value = systemLogAnnotation.value();
      addSystemLog(value);
      LOGGER.info("=========================================用戶操作日誌-後置通知結束執行......=========================================");
      }
      /**
    • <p>Discription:[保存操作日誌]</p>
    • Created on 2017年11月20日 下午3:07:33
    • @param operationContent 操作內容
    • @author:[全冉]
      */
      public void addSystemLog(String operationContent) {
      // 獲取此次請求的request對象
      HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();

      // 獲取當前登錄人的信息
      AdUser adUser = ContextHolder.getInstance().getCurrentUser();
      adUser = erpService.getAdUser(adUser);

      // 員工號
      String employeeNum = adUser.getEmplID();
      // 員工姓名
      String employeeName = adUser.getEmplName();
      // 郵箱
      String employeeEmail = adUser.getEmailAddr();
      // 瀏覽器標標識
      String webIdentifiy = getBrowserInfo(request);

      SystemLog systemLog = new SystemLog();
      systemLog.setEmployeeNum(employeeNum);
      systemLog.setEmployeeName(employeeName);
      systemLog.setEmployeeEmail(employeeEmail);
      systemLog.setOperationContent(operationContent);
      systemLog.setWebIdentifiy("瀏覽器" + webIdentifiy);

      systemLogService.save(systemLog);
      }

    /**

    • <p>Discription:[根據request獲取前臺瀏覽器標識]</p>
    • Created on 2017年11月20日 下午7:30:08
    • @param request request對象
    • @return String 瀏覽器標識
    • @author:[全冉]
      */
      private static String getBrowserInfo(HttpServletRequest request) {
      UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
      String browserInfo = userAgent.getBrowser().toString();
      return browserInfo;
      }
      }
      三.將自定義註解@SystemLogAnnotation用在切面的方法上

package com.xiaojukeji.ecm.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import com.xiaojukeji.common.annotation.SystemLogAnnotation;
import com.xiaojukeji.dao.model.Terminal;
import com.xiaojukeji.service.TerminalService;

/**

  • Description: [設備管理controller]
  • Created on 2017年11月09日
  • @author <a href="mailto: [email protected]">全冉</a>
  • @version 1.0
  • Copyright (c) 2017年 全冉公司
    */
    @Api(value = "導出相關接口", description = "導出相關接口")@RestController
    br/>@RestController
    public class ExportController {

    @Resource
    private TerminalService terminalService;

    /**

    • <p>Discription:[導出設備管理數據]</p>
    • Created on 2017年11月09日
    • @param terminal 設備實體類
    • @param response 響應參數
    • @author:全冉*/
      @GetMapping("/exportTerminal")
      br/>*/
      @GetMapping("/exportTerminal")
      br/>@ApiImplicitParams({
      @ApiImplicitParam(name = "officeBuildingName", value = "辦公區", required = false, paramType = "query"),
      @ApiImplicitParam(name = "type", value = "1:終端機 2:ipad", required = false, paramType = "query"),})
      @SystemLogAnnotation("導出設備數據")
      br/>})
      @SystemLogAnnotation("導出設備數據")
      try {
      this.terminalService.exportTerminal(terminal, response);
      }catch (Exception e) {
      e.printStackTrace();
      }
      }
      }

四.啟動項目,請求此controller裏的導出方法,在此方法的return前執行後置操作,既記錄日誌。

五.註解講解:

類註解:

@Aspect將一個類定義為一個切面類
@order(i)標記切面類的處理優先級,i值越小,優先級別越高.PS:可以註解類,也能註解到方法上

方法註解:

@Pointcut定義一個方法為切點裏面的內容為一個表達式,下面詳細介紹
@Before 在切點前執行方法,內容為指定的切點
@After 在切點後,return前執行,@AfterReturning在切入點,return後執行,如果想對某些方法的返回參數進行處理,可以在這操作
br/>@AfterReturning在切入點,return後執行,如果想對某些方法的返回參數進行處理,可以在這操作
@AfterThrowing 在切點後拋出異常進行處理
@order(i) 標記切點的優先級,i越小,優先級越高

@Pointcut註解組合使用:

上面代碼中,我們定義了一個切點,該切點只進行處理指定路徑的:

@Pointcut("execution(public com.example.DemoApplication.(..))")
private void controllerAspect(){}
現在,我們在定義一個處理其他路徑下的切點:

@Pointcut("execution(public com.demo..*(..))")
private void controllerDemo(){}
以上切點,都是分別處理不同的內容,如果我們需要一個切點來處理他們兩者,我們可以這麽配置:

@Pointcut(value = "controllerAspect() || controllerDemo()")
private void all(){}
在@Pointcut註解內,直接引用其它被@Pointcut註解過的方法名稱,這樣,該切點就可以處理兩個路徑下的方法

在多個execution表達式之間使用 ||,or表示 或,使用 &&,and表示 與,!表示 非.

execution( com.travelsky.ccboy.dao...find(..)) || execution( com.travelsky.ccboy.dao...query(..))

@Pointcut註解中的execution表達式: public com.demo..*(..)

第一個 public 表示方法的修飾符,可以用代替
第一個
表示 返回值,代表所有
com.demo.
包路徑,.表示路徑下的所有包
第三個.
表示路徑下,所有包下的所有類的方法
(..) 表示不限方法參數

關於@order(i)註解的一些註意事項:

註解類,i值是,值越小,優先級越高
註解方法,分兩種情況
註解的是 @Before 是i值越小,優先級越高
註解的是 @After或者@AfterReturning 中,i值越大,優先級越高

總結兩者的概括就是:
在切入點前的操作,按order的值由小到大執行
在切入點後的操作,按order的值由大到小執行

聚富彩票源碼下載