Spring 常用注解

Spring 常用注解

  • @Repository
    用于标注数据访问层,也可以说用于标注数据访问组件,即DAO组件。

  • @Service
    用于标注服务层,主要用来进行业务的逻辑处理。

  • @Controller
    用于标注控制层,相当于struts中的action层。

  • @Component
    不属于@Controller、@Services、@Repository的时候,我们就可以用@Component来标注这个类。
    @Controller、@Services、@Repository是对@Component的扩展。

  • @Autowired (中文: 自动连线)
    注入时使用。

  • @Autowired
    作用相当于@Autowired,只不过@Autowired按byType自动注入,而@Resource默认按 byName自动注入罢了。@Resource有两个属性是比较重要的,分是name和type,Spring将@Resource注解的name属性解析为bean的名字,而type属性则解析为bean的类型。所以如果使用name属性,则使用byName的自动注入策略,而使用type属性时则使用byType自动注入策略。如果既不指定name也不指定type属性,这时将通过反射机制使用byName自动注入策略。
    参考: @Autowired 与@Resource的区别

  • 相关链接
    Spring注解@Component、@Repository、@Service、@Controller区别
    Spring中@component的使用
    Spring中@Component的作用
    @Component注解的含义
    @Autowired用法详解

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值