美文网首页
spring 注解

spring 注解

作者: 好好学习天天引体向上 | 来源:发表于2017-01-18 17:12 被阅读0次
  • @Component 一般bean 相当于<bean id ="" class=""/>
  • @Controller 专指Controller
  • @Service 专指Service
  • @Repository 专指Dao
  • @RequestMapping 请求地址映射,支持如下属性:
    • value="" 映射地址
    • path="" 同value
    • methods={RequestMethod.XXX} 支持的方法,POST、GET、OPTIONS、DELETE、GET
    • params={"param1=value1", "param2!=value2", "param3", "!param4"} request中parameter限制,必须有param1且值为value1,必须有param2且值不为param2,必须有任意值的param3,不能有param4
    • consumes={"text/plain", "application/*"} 接收的media type,对应request中的content-type
    • produces={"text/plain", "application/*"} 返回的media type,对应request中的Accept
    • 特别的,当path使用URI Template样式时,使用 @PathVariable绑定地址中的值到方法参数
    @RequestMapping("/user/{userId}")  
     public void findUser(@PathVariable String userId, Model model) {      
     }  
    
  • @Autowired @Resource
    • Autowired 只能通过byType方式装配,与@Qualifier配合进行byName装配
    • Resource 支持byType和byName两种方式

相关文章

网友评论

      本文标题:spring 注解

      本文链接:https://www.haomeiwen.com/subject/ywhbbttx.html