@Controller @ResponseBody @ControllerAdvice @RestController @RestControllerAdvice Annotation Definition _ framework

Source: Internet
Author: User

Controller responsebody Restcontroller Controlleradvice restcontrolleradvice

@Controller

@Target ({elementtype.type})
@Retention (retentionpolicy.runtime)
@Documented
@Component public
@ Interface Controller {

    /**
     * The value may indicate a suggestion for a logical component name,
     * to be turned into a Spring bean in the case of a autodetected component.
     * @return The suggested component name, if any
    /String value () default "";

}
@ResponseBody

is usually JSON format

Role:

The annotation is used to write the object returned by the Controller method to the body data area of the response object, after the appropriate httpmessageconverter is converted to the specified format.

Time to use:

The returned data is not a page of HTML tags, but is used by some other form of data (such as JSON, XML, etc.);

@Target ({elementtype.type, elementtype.method})
@Retention (retentionpolicy.runtime)
@Documented
Public @interface responsebody {
}

========================================== @RestController

@RestController ≈ @Controller + @ResponseBody

@java. Lang.annotation.Target ({Java.lang.annotation.ElementType.TYPE})
@java. Lang.annotation.Retention ( Java.lang.annotation.RetentionPolicy.RUNTIME)
@java. lang.annotation.Documented
@ Org.springframework.stereotype.Controller
@org. Springframework.web.bind.annotation.ResponseBody
Public @interface Restcontroller {
    java.lang.String value () default "";
}
@ControllerAdvice

@ControllerAdvice Document

It is typically used to define @ExceptionHandler, @InitBinder, and @ModelAttribute methods which apply to all @RequestMappi Ng methods.

@Target ({elementtype.type})
@Retention (retentionpolicy.runtime)
@Documented
@Component public
@ Interface Controlleradvice {
    @AliasFor ("Basepackages")
    string[] Value () default {};

    @AliasFor ("value")
    string[] Basepackages () default {};

    Class<?>[] Basepackageclasses () default {};

    Class<?>[] Assignabletypes () default {};

    class<? Extends annotation>[] annotations () default {};
}
@RestControllerAdvice

@RestControllerAdvice ≈ @ControllerAdvice + @ResponseBody

The 
 @Target ({elementtype.type}) @Retention (retentionpolicy.runtime) @Documented @ControllerAdvice @ResponseBody

    Public @interface Restcontrolleradvice {@AliasFor ("basepackages") string[] Value () default {};

    @AliasFor ("value") string[] Basepackages () default {};

    Class<?>[] Basepackageclasses () default {};

    Class<?>[] Assignabletypes () default {}; class<?
Extends annotation>[] annotations () default {}; }

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.