话题很大,感觉能力有限,很难把这些东西一次说透,只能稍作一个整理,供参考了。Annotation , 注解。可以粗浅理解是一种方法,这种方法能够帮助我们简化代码或者资源配置文件,提高工作效率。越来越多的框架提供Annotation拓展,帮助我们更好完成任务。
学习中的日用而不知现象:哪怕是一个java 的出学者,都回接触java annotation的,@Override 估计不陌生,@Override 告诉编辑器覆写父类方法,如果不小心hashCode写成hoshcode这个时候IDE会提示错误的;读代码的人也很清楚这个方法覆盖父类的方法。
- packageorg.origin100.example.annotation;
- publicclassOverrideExample{
- privateStringfield;
- privateStringattribute;
- @Override
- publicinthashCode(){
- returnfield.hashCode()+attribute.hashCode();
- }
- @Override
- publicStringtoString(){
- returnfield+""+attribute;
- }
- }
Spring中注解一览:
org.springframework.web.bind.annotation
- InterfaceHierarchy
- org.springframework.web.bind.annotation.ValueConstants
- AnnotationTypeHierarchy
- org.springframework.web.bind.annotation.RequestMapping(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.ResponseBody(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.PathVariable(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.SessionAttributes(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.RequestParam(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.RequestBody(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.ResponseStatus(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.ModelAttribute(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.InitBinder(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.ExceptionHandler(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.CookieValue(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.Mapping(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.RequestHeader(implementsjava.lang.annotation.Annotation)
- EnumHierarchy
- java.lang.Object
- java.lang.Enum<E>(implementsjava.lang.Comparable<T>,java.io.Serializable)
- org.springframework.web.bind.annotation.RequestMethod
Hierarchy For Package org.springframework.stereotype
- AnnotationTypeHierarchy
- org.springframework.stereotype.Component(implementsjava.lang.annotation.Annotation)
- org.springframework.stereotype.Service(implementsjava.lang.annotation.Annotation)
- org.springframework.stereotype.Repository(implementsjava.lang.annotation.Annotation)
- org.springframework.stereotype.Controller(implementsjava.lang.annotation.Annotation)
- <prename="code"class="html"style="background-color:rgb(255,255,255);text-align:left;">org.springframework.samples.petclinic.web</pre>
- <pre></pre>
- <prename="code"class="java">@Controller
- publicclassHelloWorldController{
- @RequestMapping("/helloWorld")
- publicModelAndViewhelloWorld(){
- ModelAndViewmav=newModelAndView();
- mav.setViewName("helloWorld");
- mav.addObject("message","HelloWorld!");
- returnmav;
- }
- }</pre>配置文件:
- <?xmlversion="1.0"encoding="UTF-8"?>
- <beansxmlns="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.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.0.xsd">
- <context:component-scanbase-package="org.springframework.samples.petclinic.web"/>
- //...
- </beans>
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 , 注解。可以粗浅理解是一种方法,这种方法能够帮助我们简化代码或者资源配置文件,提高工作效率。越来越多的框架提供Annotation拓展,帮助我们更好完成任务。
学习中的日用而不知现象:哪怕是一个java 的出学者,都回接触java annotation的,@Override 估计不陌生,@Override 告诉编辑器覆写父类方法,如果不小心hashCode写成hoshcode这个时候IDE会提示错误的;读代码的人也很清楚这个方法覆盖父类的方法。
- packageorg.origin100.example.annotation;
- publicclassOverrideExample{
- privateStringfield;
- privateStringattribute;
- @Override
- publicinthashCode(){
- returnfield.hashCode()+attribute.hashCode();
- }
- @Override
- publicStringtoString(){
- returnfield+""+attribute;
- }
- }
Spring中注解一览:
org.springframework.web.bind.annotation
- InterfaceHierarchy
- org.springframework.web.bind.annotation.ValueConstants
- AnnotationTypeHierarchy
- org.springframework.web.bind.annotation.RequestMapping(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.ResponseBody(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.PathVariable(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.SessionAttributes(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.RequestParam(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.RequestBody(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.ResponseStatus(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.ModelAttribute(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.InitBinder(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.ExceptionHandler(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.CookieValue(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.Mapping(implementsjava.lang.annotation.Annotation)
- org.springframework.web.bind.annotation.RequestHeader(implementsjava.lang.annotation.Annotation)
- EnumHierarchy
- java.lang.Object
- java.lang.Enum<E>(implementsjava.lang.Comparable<T>,java.io.Serializable)
- org.springframework.web.bind.annotation.RequestMethod
Hierarchy For Package org.springframework.stereotype
- AnnotationTypeHierarchy
- org.springframework.stereotype.Component(implementsjava.lang.annotation.Annotation)
- org.springframework.stereotype.Service(implementsjava.lang.annotation.Annotation)
- org.springframework.stereotype.Repository(implementsjava.lang.annotation.Annotation)
- org.springframework.stereotype.Controller(implementsjava.lang.annotation.Annotation)
- <prename="code"class="html"style="background-color:rgb(255,255,255);text-align:left;">org.springframework.samples.petclinic.web</pre>
- <pre></pre>
- <prename="code"class="java">@Controller
- publicclassHelloWorldController{
- @RequestMapping("/helloWorld")
- publicModelAndViewhelloWorld(){
- ModelAndViewmav=newModelAndView();
- mav.setViewName("helloWorld");
- mav.addObject("message","HelloWorld!");
- returnmav;
- }
- }</pre>配置文件:
- <?xmlversion="1.0"encoding="UTF-8"?>
- <beansxmlns="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.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.0.xsd">
- <context:component-scanbase-package="org.springframework.samples.petclinic.web"/>
- //...
- </beans>
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