The topic is very big, the feeling ability is limited, it is difficult to say these things at once, can only slightly make a collation, for reference. Annotation, annotations. A superficial understanding is a method that can help us simplify code or resource configuration files and improve productivity. More and more frameworks provide annotation expansion to help us accomplish our tasks better.
The study of the daily and do not know the phenomenon: Even a Java scholar, are back to touch the Java annotation, @Override estimated is not unfamiliar, @Override tell the editor to overwrite the parent class method, If you accidentally write Hoshcode this time the IDE prompts the wrong hashcode, and the person who reads the code knows how the method overrides the parent class.
Package org.origin100.example.annotation;
public class Overrideexample {
private String field;
Private String attribute;
@Override public
int hashcode () {return
Field.hashcode () + Attribute.hashcode ();
}
@Override public
String toString () {return
field + "" + attribute;
}
}
A list of notes in spring:
org.springframework.web.bind.annotation
Interface Hierarchy org.springframework.web.bind.annotation.ValueConstants Annotation Type hierarchy
Org.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 hierarchy
Java.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 Hierarchy
org.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)
Can be seen to achieve the Java.lang in the annotation. Their usage can be seen in the "Detailed spring 3.0 based on annotation dependency injection implementation." Take a look at the official document's code sheet
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
}
}
Configuration file:
<?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.xsd
Http://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>
When compiled, the corresponding package is automatically scanned according to the Componet-scan configuration to produce the appropriate bean or injection method according to the @xxx type. I suggest that you read the official document more, and any explanation outside the document is a bit superfluous.
List of reference articles:
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