一、
package com.spring.aop.test.aspectj.test_2;
import java.util.Date;
/**
* 管理员
* @author Administrator
*
*/
public class Operator {
private Integer id ;
private String name ;
private String password ;
private Integer popedom ;
private Date loginTime ;
..set()/get()....
}
二、
package com.spring.aop.test.aspectj.test_2;
import java.util.Date;
/**
* 新闻类别信息
* @author Administrator
*
*/
public class NewsType {
private Integer id ;
private String typeName ;
private String desc ;
private Operator operator ;
private Date addTime ;
public NewsType(){}
...set()/get()...
}
三、
package com.spring.aop.test.aspectj.test_2;
import java.util.List;
public interface BasicDao<T> {
boolean save(T t) ;
boolean delete(T t) ;
boolean update(T t) ;
T get(Integer id) ;
List<T> get() ;
}
四、
package com.spring.aop.test.aspectj.test_2;
import java.util.List;
public class NewsTypeDaoImpl implements BasicDao<NewsType> {
public boolean delete(NewsType t) {
System.out.println("=======删除NewsType对象=======");
return true;
}
public NewsType get(Integer id) {
System.out.println("=======获取一个NewsType对象=======");
return new NewsType();
}
public List<NewsType> get() {
System.out.println("======获取一个NewsType对象列表======");
return null;
}
public boolean save(NewsType t) {
System.out.println("======保存NewsType对象======");
return true;
}
public boolean update(NewsType t) {
System.out.println("======更新NewsType对象======");
return true;
}
}
五、
package com.spring.aop.test.aspectj.test_2;
import java.io.*;
import java.util.Date;
public aspect NewsTypeAspect {
private static java.text.SimpleDateFormat df=new java.text.SimpleDateFormat("yyyy-MM-dd H:m:s");
//定义操作时间切入点
pointcut operatorTime(): execution(* *.*());
//定义保存切入点
pointcut saveNewsType(NewsTypeDaoImpl dao): target(dao)&&execution(boolean NewsTypeDaoImpl.save(NewsType));
//定义删除切入点
pointcut deleteNewsType(NewsTypeDaoImpl dao): target(dao)&&execution(boolean NewsTypeDaoImpl.delete(NewsType));
//输出操作开始时间
before(): operatorTime(){
System.out.println("用户操作开始时间:"+df.format(new Date()));
}
//保存时,判断用户是否拥有保存权限
boolean around(NewsTypeDaoImpl dao): saveNewsType(dao){
NewsType type = (NewsType)thisJoinPoint.getArgs()[0];
if(type.getOperator().getPopedom() > 0){
System.out.println("====开始保存NewsType对象====");
System.out.println("保存时间:"+df.format(new Date()));
return proceed(dao);
}else{
System.out.println("你暂时还没有保存NewsType对象的权利");
System.out.println("你的权限为:"+type.getOperator().getPopedom());
return false;
}
}
//删除时,要提示用户是否真的要删除此对象
boolean around(NewsTypeDaoImpl dao): deleteNewsType(dao){
boolean flag = false;
try{
NewsType type = (NewsType)thisJoinPoint.getArgs()[0];
if(type.getOperator().getPopedom() > 0){
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
System.out.println("开始删除操作......");
System.out.println("Enter a operator<Y/N>:");
String info = stdin.readLine();
if(info.indexOf("Y") != -1){
System.out.println("可以删除......");
flag = proceed(dao);
if(flag){
System.out.println("=======删除Newstype对象成功=======");
}else{
System.out.println("=======删除NewsType对象失败=======");
}
}else{
System.out.println("数据未被删除......");
}
}else{
System.out.println("你没有删除NewsType对象的权限......");
}
}catch(Exception e){
System.out.println(e.getMessage());
}
return flag;
}
}
六、
package com.spring.aop.test.aspectj.test_2;
public class NewsTypeDaoTest {
public static void main(String[] arg){
Operator op = new Operator();
op.setId(1);
op.setName("admin");
op.setPassword("password");
op.setPopedom(1);
NewsType type = new NewsType();
type.setId(1);
type.setOperator(op);
type.setTypeName("新闻");
NewsTypeDaoImpl dao = new NewsTypeDaoImpl();
// if(dao.save(type)){
//
// System.out.println("save ok......");
// }else{
//
// System.out.println("save failed......");
// }
if(dao.delete(type)){
System.out.println("delete NewsType succ......");
}else{
System.out.println("delete NewsType failed......");
}
}
}
分享到:
相关推荐
Spring AOP之基于AspectJ注解总结与案例 ,具体效果和过程看博文 http://blog.csdn.net/evankaka/article/details/45394409
Spring2.5开发 如果我们用到了AOP的话 一定需要aspectjrt.jar + aspectjweaver.jar 两个jar文件 这里面提供了 导入这两个就可以进行AOP开发了
Spring AOP的AspectJ支持jar包; 包括: com.springsource.net.sf.cglib-2.2.0.jar com.srpingsource.org.aopalliance-1.0.0.jar com.srpingsource.org.aspectj.weaver-1.68.RELEASE.jar
NULL 博文链接:https://snowolf.iteye.com/blog/1481442
一个基于@AspectJ的spring2.0 AOP应用实例,很小很简单,没有任何额外信息,最适合AOP入门学习。使用log4j打印信息。把项目直接import进myeclipse就可以使用啦......
里面包括4个例子:(1)Spring实现AOP方式之一:基于XML配置的Spring AOP (2)Spring实现AOP方式之二:使用注解配置 Spring AOP (3)Spring AOP : AspectJ Pointcut 切点 (4)Spring AOP : Advice 声明 (通知注解)
主要对Spring AOP的相关概念和简单的静态代理、动态代理以及常见的几种AOP配置方式做总结学习。主要包括:1. AOP的常见概念 2. 静态代理 3. jdk动态代理 4. Aspectj and Aspectjweaver 5. **aop-config** 6. CGLIB ...
下面小编就为大家分享一篇Spring Aop之AspectJ注解配置实现日志管理的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
Spring4.3.7的AOP依赖包-AspectJ
When to use Spring AOP and AspectJ AOP? Expert author Ramnivas Laddad shows how to combine technologies such as Spring, Hibernate, Swing, and JDBC with AspectJ. The book fully covers the latest ...
配置可以通过xml文件来进行,大概有四种方式: 1. 配置ProxyFactoryBean,显式地设置advisors, advice, target等(基于代理的AOP ) ...4. 通过<aop: aspectj-autoproxy>来配置,使用AspectJ的注解来标识通知及切入点
以公司订单管理的模型为例(大部分步骤和业务了逻辑已经删除,只保存AOP注解这一部分)Spring AOP
@AspectJ配置Spring AOP,文档,Aspect jar包, 可运行的demo,
NULL 博文链接:https://quicker.iteye.com/blog/670885
Spring AOP的一个常见问题是获取Pointcut到达类的内部方法调用。 在这个示例中,您可以在一个简单的Spring Boot示例中看到如何使用AspectJ处理节拍时间编织。 示例场景 在此示例中,将发生以下情况: 我们在上调用...
本篇文章主要介绍了详解Spring Aop实例之AspectJ注解配置,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
pring源代码各个模块作用 核心模块: 1 spring-core:核心模块 依赖注入IOC和DI的最基本实现 spring-beans:Bean工厂与装配 spring-context:上下文,即IOC...spring-aspects:集成AspectJ,Aop应用框架 spring-instrume
spring aop 自定义切面示例 aspectj 需要相应的架包支持
Spring spectJ AOP 前置通知 后置通知 返回通知 异常通知 环绕通知
NULL 博文链接:https://rain1109.iteye.com/blog/1838100