JDK comes with annotations
- @Override overrides, identifies the method that overrides its parent class
- @Deprecated has expired, indicating that the method is deprecated
- @Suppvisewarnings suppress warnings, suppress warnings
meta-annotation
@Target indicates where the annotation is used. The possible values include:
- ElemenetType.CONSTRUCTOR constructor declaration
- ElemenetType.FIELD field declaration (including enum instances)
- ElemenetType.LOCAL_VARIABLE local variable declaration
- ElemenetType.METHOD method declaration
- ElemenetType.PACKAGE package declaration
- ElemenetType.PARAMETER parameter declaration
- ElemenetType.TYPE class, interface (including annotation types) or enum declaration
- ElementType.ANNOTATION_TYPE 注解
@Retention indicates at what level the annotation information is saved. Optional RetentionPolicy parameters include:
- The RetentionPolicy.SOURCE annotation will be discarded by the compiler
- The RetentionPolicy.CLASS annotation is available in the class file, but is discarded by the VM
- RetentionPolicy.RUNTIME The JVM will also retain annotations during runtime, so the annotation information can be read through the reflection mechanism.
@Documented includes this annotation in the javadoc
@Inherited allows subclasses to inherit annotations from the parent class
Common third-party annotations
@Repository: used to mark data access components, ie DAO components
@Service: used to mark business layer components
@Transactional: Declare that all methods of this service require transaction management. A transaction is opened at the beginning of each business method
@Controller: control layer
@Component: Give the neutral class to spring management
@Autowired: Autowire, automatically inject the value from the bean container into the bean
@Path: process REST request, interface path
@Method:
There are five commonly used HTTP verbs (the corresponding SQL commands are in parentheses).
- GET (SELECT): Retrieve resource(s) from the server.
- POST (CREATE): Create a new resource on the server.
- PUT (UPDATE): Update the resource on the server (the client provides the complete resource after the change).
- PATCH (UPDATE): Update the resource on the server (client provides changed properties).
- DELETE (DELETE): Deletes the resource from the server.
There are also two less commonly used HTTP verbs.
- HEAD: Get metadata of the resource.
- OPTIONS: Get information about which properties of the resource can be changed by the client.
@Accept和@Content-Type
There are several formats as follows:
(1) @Produces("text/plain") text type
(2)@Produces("text/html") Html类型
(3) @Produces({"application/xml"}) Xml type
(4)@Produces({ "application/json"}) Json类型
Two or more MIME types can be annotated at one time. The format is: {"application/xml", "application/json"} This means that both can be used, but the former is generally selected when choosing, namely application/xml, Because it appeared for the first time.
@Queryparam: Specifies that the parameters in the URL appear in the form of key-value pairs, while in the program @QueryParam("from") int from reads the value of from in the URL,
For example: URL input is: users?from=100&to=200&orderBy=age&orderBy=name
@Pathparam: Only the value of the parameter appears in the URL, not the key-value pair
For example: /users/100