小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

spring用Aop實(shí)現(xiàn)計(jì)算器驗(yàn)證(注解方式)

 魏祖清 2016-09-11
//抽象類:ArithnmeticCalulator
public interface ArithnmeticCalulator {
int add(int i,int j);
int sub(int i,int j);
int mul(int i,int j);
int div(int i,int j);
}
//實(shí)現(xiàn)抽象類:ArithnmeticCalulator類
@Component("arithnmeticCalulator")
public class ArithnmeticCalulatorImpl implements ArithnmeticCalulator {
實(shí)現(xiàn)方法省去.....
}
LogginAspect實(shí)現(xiàn)
//把這個(gè)類聲明為一個(gè)切面,需要吧該類放入IOC容器中,在聲明一個(gè)切面
@Aspect
@Component
public class LogginAspect {
// 定義一個(gè)方法,用于聲明切入點(diǎn)的表達(dá)式,一般在放中不需要添加其他的代碼
@Pointcut("execution(* com.wzq.spring.aop.impl.*.*(..))")
public void declareJoinPointExpression() {

}

@Before("declareJoinPointExpression()")
public void beforeMethod(JoinPoint joinPoint) {
//獲取ArithnmeticCalulator的method方法
String methodName = joinPoint.getSignature().getName();
//獲取ArithnmeticCalulator的method值
List<Object> args = Arrays.asList(joinPoint.getArgs());
System.out.println("The method " + methodName + "begins" + args);
}

// 后置通知:在目標(biāo)方法執(zhí)行后執(zhí)行的通知,執(zhí)行的通通知 //后置通知不會(huì)返回結(jié)果
@After("declareJoinPointExpression()")
public void afterMethod(JoinPoint joinPoint) {
String methodName = joinPoint.getSignature().getName();
System.out.println("The method " + methodName + "ends");
// 異常通知
@AfterThrowing(value ="declareJoinPointExpression()", throwing = "ex")
public void afterThrowing(JoinPoint joinPoint, Exception ex) {
String methodName = joinPoint.getSignature().getName();
System.out.println("The method " + methodName + "execution" + ex);
}
}
XML配置
<!-- 配置bean -->
<bean class="com.wzq.spring.aop.xml.ArithnmeticCalulatorImpl" id="arithnmeticCalulator"></bean>
<!-- 配置切面的bean -->
<bean id="logginAspect" class="com.wzq.spring.aop.xml.LogginAspect"></bean>
main方法
public class Main {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"applicationContext.xml");
ArithnmeticCalulator arithnmeticCalulator = ctx
.getBean(ArithnmeticCalulator.class);
int result = arithnmeticCalulator.sub(6, 6);
System.out.println("result:" + result);
int result1=arithnmeticCalulator.div(10, 0);
System.out.println(result1);
}
}

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多