• 注解:就是一个类,使用@注解名称
  • 开发中:使用注解 取代 xml配置文件。

 

 

6.4.1 @Component

@component取代<bean class="">

6.4.2 @Component("id")

取代 <bean id="" class="">

6.4.4 web开发,提供3个@Component注解衍生注解(功能一样)取代<bean class="">

@Repository(“名称”):dao层

@Service(“名称”):service层

@Controller(“名称”):web层

 

@Autowired:自动根据类型注入

@Qualifier(“名称”):指定自动注入的id名称

 

@Resource(“名称”)

@ PostConstruct 自定义初始化

@ PreDestroy 自定义销毁

 

 

6.4.5 使用案例

第一个案例

Spring---------- 注解注入

Spring---------- 注解注入

 

Spring---------- 注解注入

 

第二个案例

Spring---------- 注解注入

Spring---------- 注解注入

 

第三个案例

Spring---------- 注解注入

Spring---------- 注解注入

 

第四个案例

Spring---------- 注解注入

Spring---------- 注解注入

 

第五个案例

Spring---------- 注解注入

 

第六个案例

Spring---------- 注解注入

Spring---------- 注解注入

相关文章:

  • 2021-07-06
  • 2021-12-26
  • 2021-05-25
  • 2021-10-26
猜你喜欢
  • 2021-08-21
  • 2021-11-09
  • 2021-09-22
  • 2020-05-03
  • 2021-09-05
相关资源
相似解决方案