JDK comes with annotations
- @Override Override to identify a method that overrides its parent class
- The @Deprecated has expired, indicating that the method is not recommended for use
- @Suppvisewarnings suppress warnings, suppress warnings
Meta Annotations
@Target indicates where the annotation is used, the desirable values are:
- Elemenettype.constructor Constructor Declaration
- Elemenettype.field domain declarations (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 type) or enum declaration
- Elementtype.annotation_type annotations
@Retention indicates at what level the annotation information is saved. The optional retentionpolicy parameters include:
- Retentionpolicy.source annotations will be discarded by the compiler
- Retentionpolicy.class annotations are available in the CLASS file, but are discarded by the VM
- The Retentionpolicy.runtime JVM also retains annotations at run time, so the information of the annotations can be read through the reflection mechanism.
@Documented include this annotation in Javadoc
@Inherited allow subclasses to inherit annotations from the parent class
Common third-party annotations
@Repository: Used to label data access Components, DAO components
@Service: For labeling business layer components
@Transactional: Declares that all methods of this service require transaction management. Every business method starts with a transaction open
@Controller: Control layer
@Component: Give the neutral class to spring management
@Autowired: Automatic assembly, automatically injecting values from the bean container into the bean
@Path: Handling rest requests, interface paths
@Method:
The usual HTTP verbs have the following five (the corresponding SQL command in parentheses).
- GET (SELECT): Remove resources from the server (one or more items).
- POST (Create): Creates a new resource on the server.
- PUT (UPDATE): Updates the resource on the server (the client provides a full resource after the change).
- PATCH (UPDATE): Updates the resource on the server (the client provides changed properties).
- Delete: Deletes a resource from the server.
There are also two infrequently used HTTP verbs.
- HEAD: Gets the metadata for the resource.
- OPTIONS: Gets information about which properties of a resource are available to the client to change.
@Accept and @content-type
@Accept: Represents the data format that the interface will return to the client @content-type: represents the data format that the client sends to the server side. This is to write the rest interface when the definition of normal if the server does not define the accept but added the words will be reported 404, did not find the corresponding interface.@ProducesRepresents the MIME data type returned by a class or method
There are several formats as follows:
(1) @Produces ("Text/plain") text type
(2) @Produces ("text/html") HTML type
(3) @Produces ({"Application/xml"}) XML type
(4) @Produces ({"Application/json"}) JSON type
You can annotate two or more MIME types at one time, such as {"Application/xml", "Application/json"} which means both can be used, but the choice is usually the former, that is, Application/xml, Because it appears for the first time.
@ConsumesRepresents the MIME type that a resource can accept@Queryparam and @pathparam
@Queryparam: Specifies that the parameter in the URL appears as a key-value pair, whereas in the program @QueryParam ("from") an int from reads out the value from the URL,
For example: URL input: users?from=100&to=200&orderby=age&orderby=name
@Pathparam: Only the value of the parameter appears in the URL and no key-value pairs appear
Example:/users/100
Java system annotations diagram
Java Common annotations