切入業(yè)務(wù)日志-創(chuàng)新互聯(lián)

創(chuàng)建接口BizAnnotation.java

創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比遼陽縣網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式遼陽縣網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋遼陽縣地區(qū)。費(fèi)用合理售后完善,十多年實(shí)體公司更值得信賴。

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

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

    //操作模塊
    String moduleName();
    //操作
    String option();

}

-----------------------------------------------------------默默無聞的分割線-----------------------------------------------------------

添加業(yè)務(wù)日志DAO接口bizLoggerDao,此處未貼代碼。

添加業(yè)務(wù)日志DAO接口bizLoggerDao實(shí)現(xiàn)類bizLoggerDaoImpl,此處未貼代碼。

-----------------------------------------------------------默默無聞的分割線-----------------------------------------------------------

標(biāo)記業(yè)務(wù)接口StudentService.java

import java.util.List;
import com.shenzhen.management.pojo.Student;
public interface StudentService {
public List<Student> getAllStudents();
@BizAnnotation(moduleName="Student Management",option="Add Student")
public void addStudent(Student student);
}

-----------------------------------------------------------默默無聞的分割線-----------------------------------------------------------

添加業(yè)務(wù)接口StudentService.java實(shí)現(xiàn)類StudentServiceImpl.java,此處未貼代碼。

-----------------------------------------------------------默默無聞的分割線-----------------------------------------------------------

創(chuàng)建業(yè)務(wù)日志類BizLogger.java

import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import com.opensymphony.xwork2.ActionContext;
import com.shenzhen.management.dao.BizLoggerDao;
import com.shenzhen.management.service.BizAnnotation;

public class BizLogger {

private BizLoggerDao bizLoggerDao;

        public void log(JoinPoint joinPoint, Object returnObj) {

        //方法名
        String methodName = joinPoint.getSignature().getName();
        //參數(shù)
        Object[] parameters = joinPoint.getArgs();
        //返回值
        Object returnValue = returnObj;
        //獲取模塊,操作
        Method method = ((MethodSignature)joinPoint.getSignature()).getMethod();
        BizAnnotation bizAnnotation = method.getAnnotation(BizAnnotation.class);
        String moduleName = bizAnnotation.moduleName();
        String option = bizAnnotation.option();
        //獲取用戶ID
        String userId = getUserId();
        //獲取用戶IP
        String ip = getIP();
        //執(zhí)行插入
        bizLoggerDao.saveLog(選擇需要保存的數(shù)據(jù)作為參數(shù));
    }

    public String getTime()
    {
    Date now = new Date();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    String time = dateFormat.format( now );
    return time;
    }

    public String getUserId()
    {
    Map session =  ActionContext.getContext().getSession();
    String userId = (String)session.get("userId");
    return userId;
    }

    public String getIP() {

    HttpServletRequest request =  org.apache.struts2.ServletActionContext.getRequest();

        String ip = request.getHeader("x-forwarded-for");
        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        return ip;
    }

public BizLoggerDao getBizLoggerDao() {
return bizLoggerDao;
}

public void setBizLoggerDao(BizLoggerDao bizLoggerDao) {
this.bizLoggerDao = bizLoggerDao;

}

-----------------------------------------------------------默默無聞的分割線-----------------------------------------------------------

配置applicationContext.xml

  <bean id = "bizLoggerDao" class="com.shenzhen.management.dao.impl.BizLoggerDaoImpl">
      <property name="sqlSessionTemplate" ref="sqlSessionTemplate"></property>
    </bean>
    <bean id="bizLogger" class="com.shenzhen.management.util.log.BizLogger">
      <property name="bizLoggerDao" ref="bizLoggerDao" />
    </bean>
<aop:config>
 <aop:pointcut id="bizLogPointcut" expression="execution(* com.shenzhen.management.service.*.*(..))"/>
      <aop:aspect id="bizLogAspect" ref="bizLogger">
        <aop:after-returning method="log" returning="returnObj" pointcut-ref="bizLogPointcut"/>
      </aop:aspect>
    </aop:config>

創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國云服務(wù)器,動(dòng)態(tài)BGP最優(yōu)骨干路由自動(dòng)選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡(luò)助力業(yè)務(wù)部署。公司持有工信部辦法的idc、isp許可證, 機(jī)房獨(dú)有T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確進(jìn)行流量調(diào)度,確保服務(wù)器高可用性。佳節(jié)活動(dòng)現(xiàn)已開啟,新人活動(dòng)云服務(wù)器買多久送多久。

新聞名稱:切入業(yè)務(wù)日志-創(chuàng)新互聯(lián)
分享地址:http://www.muchs.cn/article4/peioe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、云服務(wù)器、企業(yè)網(wǎng)站制作、小程序開發(fā)、網(wǎng)站策劃網(wǎng)站改版

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)