Spring+spring Boot+mybatis Frame Annotation Analysis

Source: Internet
Author: User
Tags echo message

Note Development for spring boot under Restful style
The restful style often used by e-commerce websites is just a development idea, not a development framework, and today's technology does not fully implement restful styles. RESTful style is an architectural concept that perfectly interprets the HTTP protocol restful way requires a restful style of front controller to be configured with /to identify the url-patternrequestmapping (value = "/viewitems/{id}" string id) Inside Java class use @pathvariable ("id") annotation for parameter binding String ID or bind Java Bean's Bean property
@SpringBootApplication
Springboot provides a unified annotation @springbootapplication to replace these three annotations @configuration, @EnableAutoConfiguration, @ComponentScan, simplifying the configuration of the program.
@EnableAutoConfiguration
@EnableAutoConfiguration: The ability to automatically configure the spring context, to try to guess and configure the Bean class you want, is automatically configured automatically based on your classpath and your bean definition.
@ComponentScan
@ComponentScan: Automatically scans all classes marked with @component under the specified package and registers as beans, including @component @service, @Repository, @Controller, of course.
@Configuration
The @Configuration is labeled on the class as a <beans> in the spring XML configuration file, whichacts as: Configuring the Spring Container (application context) to load annotations for the configuration XML file. The class is annotated with @configuration, the equivalence is configured with XML beans, and the @bean annotation method is equivalent to the configuration bean in XML. 
@EnableWebMvc
To Customize the default configuration in Java, you can simply implement the Webmvcconfigurer interface, or inherit the Webmvcconfigureradapter and rewrite the method you need: @ConfigurationclassWebmvcconfig extends Webmvcconfigureradapter {@Override Public voidaddresourcehandlers (Resourcehandlerregistry registry) {Registry.addresourcehandler ("swagger-ui.html"). Addresourcelocations ("classpath:/meta-inf/resources/"); Registry.addresourcehandler ("/webjars/**"). Addresourcelocations ("classpath:/meta-inf/resources/webjars/"); }
}
@Override
Override is a marker annotation type, which is used as a labeling method. It illustrates the way that the annotated method overloads the parent class and plays the role of the assertion. If you write wrong, the compiler can detect what is wrong, which ensures that you are actually rewriting the correct method.
@Validated (value={})
This annotation refers to the grouping check, which is paired with Bindingresult, and the Modelandview model object can return the error information to the interface.
@ModelAttribute ("")
The annotation echoes back to the key inside the request to handle the echo message:
No matter what you enter, correct commits, errors are echoed, and return values can be returned to the interface, the simplest echo with the data type of ECHO, directly using Model.addattribute ("allerrors   ", allerrors); Configure the virtual directory of the picture with access path, Tomcat double-click ->model-> selected in the second Add external Web module
@Autowired
2.5 set , get method.
@RequestMapping ("FileUpload")
Annotations specify which specific URL requests can be processed by the controller.
@ApiOperation and @apiparam
= "Interface description", HttpMethod = "Interface request Mode", response= "interface return parameter type", notes = "interface Release Notes", other parameters can refer to the source code, not spring comes with annotations, But swagger in the com.wordnik.swagger.annotations.ApiOperation;
= "parameter Required", name = "parameter name", value = "parameter description".
@Api
Modifies the entire class to describe the role of the controller.
@ApiOperation
Describes a method of a class, or an interface.
@ApiModel
Use the model object to receive the parameter.
@ApiParam
true ) @RequestParam String tokenweb front-end /Mobile HTTP request method: Directly append the parameters to the URL, or use the Ajax method to submit the form.
@ApiProperty
A field that describes an object when it is received with an object.
@ApiResponse
The HTTP response contains 1 requests and a parameter description.
@ApiResponses
HTTP response Overall description.
@ApiModelProperty
Object properties are @ApiModelProperty used on fields in and out of parameter objects.
@RestController
@RestController Note is that it inherits from @controller annotations. 4. Prior to 0, Spring MVC components used @controller to identify the current class as a controller servlet. With this feature, we can develop rest services without the use of @controller and dedicated @restcontroller. Annotations themselves use @controller and @responsebody annotations. Classes that use this annotation are treated as a controller that uses @requestmapping's method and has a default @responsebody annotation.
@Api used for protocol set descriptions on controller classes
@ApiOperation used on the controller's method for the protocol set description
@ApiResponses belongs to the response set in the controller's method.
@ApiResponse used in @ApiResponses belong to the response set
@ApiImplicitParams is a non-object parameter set used on the controller's method
@ApiImplicitParam is a non-object parameter set used in the @apiimplicitparams method
@ApiModel use to describe the meaning of the returned object on the return object class
@component
Instantiate the normal pojo into the spring container, equivalent to the <bean id= "" class= "/> in the configuration file
@RequestBody
This annotation is used to read the body portion of the request requests, parse using the system's default configuration Httpmessageconverter, and then bind the corresponding data to the object to be returned. The object data returned by the Httpmessageconverter is then bound to the parameters of the method in the controller
@Data
Annotations on classes provide read and write properties for classes, plus the Equals (), Hashcode (), toString () methods are also provided
@Builder
Annotations on the class, provide an internal Builder for the class
@Synchronized
Annotations on methods, providing synchronous locks for methods
@Log4j
Annotations on a class, provide a log object with a log4j property named log for the class
@Slf4j
Annotations on a class, provide a log object with a log4j property named log for the class
@Service
For labeling business layer components
@Controller
For labeling control-layer components, such as action in struts
@Repository
For labeling data Access Components, DAO components
@Component
We can use this annotation to annotate components when they are poorly categorized.
@Autowired
@Qualifier ("Chinese") when there are two implementation classes for an interface, you must use @qualifier to specify which implementation class to inject, otherwise you can omit and write only @autowired. <mvc:annocation-driven/> Annotations in the form of a JSON converter, you can set the conversion between JSON and the bean using @responsebody annotations directly: The annotation is used to write the object returned by the controller's method to the body data area of the response object after it is converted to the specified format by the appropriate Httpmessageconverter
@ModelAttribute

@RequestParam
You can pass the request parameter to the request method by using the @RequestParam at the processing method entry.
@PathVariable
Bind URL placeholder to enter parameter
@ExceptionHandler
Annotation to method, the method is executed when an exception occurs
@ControllerAdvice
Makes a contoller a global exception-handling class, with methods annotated by the @exceptionhandler method to handle exceptions that occur with all controllers
@ResponseBody

The annotation is used to write the object returned by the controller's method to the body data area of the response object after the appropriate httpmessageconverter is converted to the specified format. When to use: The returned data is not a page of HTML tags, but a data in some other format (JSON, XML, etc.) when we mark the @restcontroller on the controller, All the methods that are equivalent to the controller are labeled @responsebody
The function of the @responseBody annotation is to write to the body of the response object after the object returned by the controller is converted to the specified format by the appropriate converter, which is usually used to return JSON data or XML data. Instead of going to the processor after using this annotation, the data is written directly to the input stream, and his effect is equivalent to outputting the data in the specified format through the response object.
@RequestMapping ("/login")

@ResponseBody
Public user login (user user) {
return user;
}
User field: UserName pwd
Then the data received at the front desk is: ' {' userName ': ' xxx ', ' pwd ': ' xxx '} '

The effect is equivalent to the following code:
@RequestMapping ("/login")
public void login (user user, httpservletresponse response) {
Response.getWriter.write (jsonobject.fromobject (user). ToString ());
}

Details:
A JSON jar package from Google that wraps the object back in JSON at any time. Gson Gson = new Gson (); String JSON = Gson.tojson (object);
@Param
1, use @param annotations when writing SQL statements in the following way: @Select ("Select column from table where UserID = #{userid}")     Public intSelectColumn (intuserid) When you use the @param annotation to declare a parameter, you can use #{} or ${}. @Select ("Select column from table where UserID = ${userid}")     Public intSelectColumn (@Param ("userid")intuserid) When you do not use @param annotations to declare parameters, you must use the #{} method.    If you use ${}, you will get an error. @Select ("Select column from table where UserID = ${userid}")     Public intSelectColumn (@Param ("userid")intuserid);2, the parameter can only have one and is javabean when the @param annotation is not used without the @param annotation.    The JavaBean property can be referenced in the SQL statement, and only the properties of the JavaBean are referenced. //The ID here is the user's property@Select ("select * from Table where id = ${id}") enchashment Selectuserbyid (user user);
Recalling

Gorgeous costume.
The soft lines
Just to prove you were here.
Smile on the Face
A fragile life.
Just to imply that you're still alive.
You were miles away.
Whisper what is the
The lamp in front of the bed
To reveal something.
The crowd on the roadside
Again in the head to ponder which one
You and I used to be
What do you remember after thousand years?
I've seen the Galloping desert
Experience the silent Yellow River
Feel the end of time
To reproduce the demon's nightmare.
Happy Endless Starry Sky
The light of Sadness
The alternation of night and Dawn
Is the change of good and evil
The rebirth of Ice and fire
Beautiful
Just for the love of

Spring+spring Boot+mybatis Frame Annotation Analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.