Spring常用注解详解大全

                                                          

创作目的:

      避免我们在面试或者写项目时的尴尬

开始干!

1,@Controller注解

用于标注控制层组件
如果@Controller不指定其value【@Controller】,则默认的bean名字为这个类的类名首字母小写,如果指定value【@Controller(value="UserAction")】或者【@Controller("UserAction")】,则使用value作为bean的名字。

@Controller
@RequestMapping("/medicine")
public class MedicineController {
    ApplicationContext context =new ClassPathXmlApplicationContext("applicationContext-jdbc.xml");
    DoctorService ds =(DoctorService) context.getBean("doctorService");
    MedicineService ms =(MedicineService) context.getBean("medicineService");
    @RequestMapping(value="/doctor",method= RequestMethod.GET)

2,@Resource

默认按照byName方式进行bean匹配,当找不到与名称匹配的bean才会按类型装配,由J2EE提供,需要导入包javax.annotation.Resource,@Resource的作用相当于@Autowired,只不过@Autowired按照byType自动注入。
(1)、@Resource后面没有任何内容,默认通过name属性去匹配bean,找不到再按type去匹配
(2)、指定了name或者type则根据指定的类型去匹配bean
(3)、指定了name和type则根据指定的name和type去匹配bean,任何一个不匹配都将报错

3,@Service注解

用于标注业务层组件。
@Service(“userService”)注解是告诉Spring,当Spring要创建UserServiceImpl的的实例时&#

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值