1. 程式人生 > >SSM框架之Spring的常用註解超級簡潔版

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環繞通知