U
U
user.2018-11-25 23:16:33
Java
user., 2018-11-25 23:16:33

SpringBoot explain the difference between @Controller and @restcontroller annotations?

I started to study the Springboot Framework and got a little confused.
As far as I understand, when developing web applications in spring, there are two types of controllers
@Controller and @Restcontroller. What is the difference between them?
If I need to return for example a static html page should I use the @controller annotation?
If I need to return a json/xml string then should I use @restcontroller?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aol-nnov, 2018-11-26
@aol-nnov

why not read the documentation? because it's so easy in IDE.

/**
 * A convenience annotation that is itself annotated with
 * {@link Controller @Controller} and {@link ResponseBody @ResponseBody}.
 * <p>
 * Types that carry this annotation are treated as controllers where
 * {@link RequestMapping @RequestMapping} methods assume
 * {@link ResponseBody @ResponseBody} semantics by default.
 *
 * <p><b>NOTE:</b> {@code @RestController} is processed if an appropriate
 * {@code HandlerMapping}-{@code HandlerAdapter} pair is configured such as the
 * {@code RequestMappingHandlerMapping}-{@code RequestMappingHandlerAdapter}
 * pair which are the default in the MVC Java config and the MVC namespace.
 *
 * @author Rossen Stoyanchev
 * @author Sam Brannen
 * @since 4.0
 */

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question