SSM框架之Spring的常用注解超级简洁版

1.注册对象

@Component("user")
@Service("user") //service层
@Controller("user") //web层
@Repository("user") //dao层

2.修改对象的作用范围

@Scope(scopeName="prototype")

3.值类型注入

@Value("tom")
private  String name;

@Value("tom")
public void setName(String name){
    this.name=name;
}

4.引用类型注入

@Autowired
private Car car;

@Autowired //自动装配,多个对象,根据名称
@qualifier("car2")
private Car car;

@Resource(name="car") //手动注入,指定名称
private Car car;

5.初始化方法

@PostConstruct
public void init(){}

6.销毁方法

@PreDestrory
public void destory(){}

7.事务

@Transactional

8.AOP

@aspect切面

@pointcut 切点

@before 指定方法是前置通知,并制定切入点

@afterreturning 后置通知

@afterthrowing 异常通知

@after 最终通知

@around环绕通知

猜你喜欢

转载自blog.csdn.net/lcgoing/article/details/84884251