话题很大,感觉能力有限,很难把这些东西一次说透,只能稍作一个整理,供参考了。Annotation , 注解。可以粗浅理解是一种方法,这种方法能够帮助我们简化代码或者资源配置文件,提高工作效率。越来越多的框架提供Annotation拓展,帮助我们更好完成任务。

学习中的日用而不知现象:哪怕是一个java 的出学者,都回接触java annotation的,@Override 估计不陌生,@Override 告诉编辑器覆写父类方法,如果不小心hashCode写成hoshcode这个时候IDE会提示错误的;读代码的人也很清楚这个方法覆盖父类的方法。

package org.origin100.example.annotation;public class OverrideExample {private String field;private String attribute;@Overridepublic int hashCode() {return field.hashCode() + attribute.hashCode();}@Overridepublic String toString() {return field + " " + attribute;}
}

Spring中注解一览:

org.springframework.web.bind.annotation

Interface Hierarchyorg.springframework.web.bind.annotation.ValueConstants
Annotation Type Hierarchyorg.springframework.web.bind.annotation.RequestMapping (implements java.lang.annotation.Annotation)
org.springframework.web.bind.annotation.ResponseBody (implements java.lang.annotation.Annotation)
org.springframework.web.bind.annotation.PathVariable (implements java.lang.annotation.Annotation)
org.springframework.web.bind.annotation.SessionAttributes (implements java.lang.annotation.Annotation)
org.springframework.web.bind.annotation.RequestParam (implements java.lang.annotation.Annotation)
org.springframework.web.bind.annotation.RequestBody (implements java.lang.annotation.Annotation)
org.springframework.web.bind.annotation.ResponseStatus (implements java.lang.annotation.Annotation)
org.springframework.web.bind.annotation.ModelAttribute (implements java.lang.annotation.Annotation)
org.springframework.web.bind.annotation.InitBinder (implements java.lang.annotation.Annotation)
org.springframework.web.bind.annotation.ExceptionHandler (implements java.lang.annotation.Annotation)
org.springframework.web.bind.annotation.CookieValue (implements java.lang.annotation.Annotation)
org.springframework.web.bind.annotation.Mapping (implements java.lang.annotation.Annotation)
org.springframework.web.bind.annotation.RequestHeader (implements java.lang.annotation.Annotation)
Enum Hierarchyjava.lang.Object
java.lang.Enum<E> (implements java.lang.Comparable<T>, java.io.Serializable)
org.springframework.web.bind.annotation.RequestMethod

Hierarchy For Package org.springframework.stereotype

Annotation Type Hierarchyorg.springframework.stereotype.Component (implements java.lang.annotation.Annotation)
org.springframework.stereotype.Service (implements java.lang.annotation.Annotation)
org.springframework.stereotype.Repository (implements java.lang.annotation.Annotation)
org.springframework.stereotype.Controller (implements java.lang.annotation.Annotation)
可以看出都实现了java.lang中的Annotation。它们的用法可以参见《 详解Spring 3.0基于Annotation的依赖注入实现》。看看官方文档的代码片
org.springframework.samples.petclinic.web


@Controller
public class HelloWorldController {@RequestMapping("/helloWorld")public ModelAndView helloWorld() {ModelAndView mav = new ModelAndView();mav.setViewName("helloWorld");mav.addObject("message", "Hello World!");return mav;}
}
配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"><context:component-scan base-package="org.springframework.samples.petclinic.web"/>// ...</beans>

编译的时候自动会根据componet-scan 配置扫描相应的package根据@xxx类型生产相应的bean 或者注入方法。建议大家多看官方文档,文档之外任何解释都有点多余。

参考文章列表:

http://www.ibm.com/developerworks/cn/opensource/os-cn-spring-iocannt/index.html

http://static.springsource.org/spring/docs/3.0.x/reference/mvc.html#mvc-annotation-driven

Annotation 和Spring Annotation 知识整理相关推荐

  1. Spring AOP 知识整理

    为什么80%的码农都做不了架构师?>>>    AOP知识整理 面向切面编程(AOP)通过提供另外一种思考程序结构的途经来弥补面向对象编程(OOP)的不足.在OOP中模块化的关键单元 ...

  2. Spring Annotation知识梳理

    2019独角兽企业重金招聘Python工程师标准>>> Spring annotation:(目的:减少applicationContext.xml文件配置) 使用注解时需要添加扫描 ...

  3. Spring学习篇:IoC知识整理(一)

    现在正通过spring的官方文档学习spring,将自己学习时的点点滴滴记录下来. Ioc知识整理(一): IoC (Inversion of Control) 控制反转. 1.bean的别名 我们每 ...

  4. @Query Annotation in Spring Data JPA--转

    原文地址:http://javabeat.net/spring-data-jpa-query/ In my previous post on Spring Data, I have explained ...

  5. Spring Annotation(@Autowire、@Qualifier)

    Spring Annotation(@Autowire.@Qualifier) 1 <?xml version="1.0" encoding="UTF-8" ...

  6. DWR的学习文档(Hello World,类型转换,Spring,Annotation)

    來源:http://www.iteye.com/topic/40313 DWR是作为远程调用的ajax框架,将服务端的java类,方法和浏览器的javascript的类,方法对应起来.现在官方最新的版 ...

  7. Invalid default: public abstract java.lang.Class org.mybatis.spring.annotation.MapperScan.factoryBe

    错误信息: java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class o ...

  8. 2021最新Spring Security知识梳理

    2021最新Spring Security知识梳理 一.SpringSecurity 框架简介 Spring 是非常流行和成功的 Java 应用开发框架,Spring Security 正是 Spri ...

  9. *Java软件开发面试知识整理*

    Java软件开发面试知识整理 围绕以下几点回答问题:是什么.为什么.什么时候用.项目实现.解决什么问题.遇到的困难 谈谈你对Java和C的理解? Java: 面向对象.Unicode:可以跨平台(JV ...

最新文章

  1. 与癌症作战的 12 家 AI 公司,八仙过海各显神通
  2. 【手写系列】纯手写实现JDK动态代理
  3. 如何处理新建的SAP CRM产品category没有出现在列表的问题
  4. java计算两个文本框的值,java 文本框自动获取另外两个文本框的值的乘积
  5. 现代软件工程 教学计划 中国科学技术大学-微软亚洲研究院联合培养班
  6. 情感分析算法从原理到PaddlePaddle实战全解
  7. ckeditor 图片上传_开发问题:Django使用ckeditor上传到七牛云
  8. c++分治法求最大最小值实现_你所不了解的分治算法
  9. 2008年卫星地图_黄河入海口1984年-2016年,34年卫星地图变化
  10. python前端工资_前端的工资分布情况-你又拖后退了吗?
  11. 基于各系统平台(RedHat Linux、SUSE Linux、CentOS、SUN Solaris10) FTP服务的配
  12. 【Java常见异常】InaccessibleObjectException异常处理方法
  13. 设计师谈中望CAD2010应用心得 作者:刘国勤
  14. 网站服务器需不需要装杀毒软件,服务器要不要装杀毒软件
  15. onActivityResult不能收到setResult(RESULT_OK, intent);的回调
  16. 攻防世界 pwn进阶区----No.012 babyfengshui 解题思路
  17. winhex 13.5注册版
  18. RS232/RS485/CAN总线
  19. 网络协议 终章 - GTP 协议:复杂的移动网络 1
  20. 计算机上标和下标的快捷键,三步法教你迅速在Word中设置上标和下标,上标与下标的快捷键是什么?...

热门文章

  1. TIME_WAIT详解
  2. armv7与armv8 cp15 cache指令
  3. ScriptManager脚本管理器
  4. 在线IPv4转换为IPV6,IPV6转为IPV4的工具
  5. case when 的使用
  6. small rtos51学习资料收集
  7. Win10系统的SurfacePro4的触摸笔如何使用
  8. 微软PPM 软件 android,微软Surface Duo带来改进后的手写笔支持 Android系统也可顺滑无迟滞...
  9. potplayer清晰度设置
  10. Android横竖屏屏幕方向设置