Through the recent projects, many of the problems encountered in the project are due to the use of the annotations are not familiar results in the development efficiency is not high, so I spent some time, the most common annotations in the springboot to organize and summarize, I hope to help everyone.
(1) @restcontroller and @requestmapping annotations are the most important in springboot.
@RestController annotations, which inherit from @controller annotations. When implementing a restful Web services, response will always be sent through the response body. To simplify development, Spring 4.0 provides a dedicated version of the controller. The following is the definition of the @restcontroller implementation:
@RequestMapping annotations provide routing information.
It is an annotation used to process request address mappings and can be used on classes or methods. On a class, the method that represents all response requests in a class is the parent path of the address.
The note has six properties:
Params: Specifies that some parameter values must be included in the request before the method is processed.
Headers: Specifies that certain header values must be included in the request in order for the method to process requests.
Value: Specifies the actual address of the request, the specified address can be URI Template mode
Method: Specifies the type of method requested, GET, POST, PUT, delete, etc.
Consumes: Specifies the type of submission to process the request (Content-type), such as application/json,text/html;
Produces: Specifies the type of content returned, only if the type in the request header (Accept) contains the specified type to return
(2) @ResponseBody
@Responsebody indicates that the return result of the method is written directly to the HTTP response body
Generally used when fetching data asynchronously, after using @requestmapping, the return value is usually resolved to a jump path,
After adding @responsebody, the returned result is not parsed into the jump path, but is written directly to the HTTP response body.
For example, asynchronously fetching JSON data, plus @responsebody, will return the JSON data directly.
(3) @RequestBody Insert the HTTP request body into the method, using the appropriate httpmessageconverter to write the request body to an object.
(4) @Autowired annotations, typically combined with @componentscan annotations, to automatically inject a service or DAO-level bean
(5) @Service
Components typically used to decorate the service layer
(6) @Data, for the creation of the method of get and set in the entity class, it is not necessary to implement the get and set method.
(7)@Component:
We can use this annotation to annotate components when they are poorly categorized.
(8)@RequestParam:
Used in front of the method's parameters.
(9) @Transactional:
In the spring container, we manually annotated that the @bean will be loaded first, and the framework will not re-instantiate the other Platformtransactionmanager implementation classes.
Then in the service, the method that is @Transactional annotated will support the transaction. If the annotation is on a class, all methods of the entire class support the transaction by default.
For the same project there are more than one transaction manager how to handle, as shown below, can be resolved;
(10) Refer to the website:
http://blog.csdn.net/catoop/article/details/50595702
Http://www.cnblogs.com/m4tech/p/6610301.html
(11) Summary: About Springboot in the comments there are many, these are I encountered in the project many places to use, I feel very important, very good use of annotations, can quickly improve the speed of coding, good coding habits is very important, I am in the project is because not careful, the test will have a lot of bugs, Careful for us is very important, take everything seriously, I believe we will soon grow up, refueling.