Skip to content

Commit bb5ef52

Browse files
spring controller question
1 parent de62f9f commit bb5ef52

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ This repository contains interview questions for Java developers.
103103
- [What is the difference between @Resource and @Autowired annotations?](spring.md#what-is-the-difference-between-resource-and-autowired-annotations)
104104
- [What is the feature in Spring Boot for setting up the dependencies?](spring.md#what-is-the-feature-in-spring-boot-for-setting-up-the-dependencies)
105105
- [Where does Spring Boot application begin?](spring.md#where-does-spring-boot-application-begin)
106+
- [What is the difference between @Controller and @RestController annotations?](spring.md#what-is-the-difference-between-controller-and-restcontroller-annotations)
106107

107108
## Servlet
108109
- [What is servlet?](servlet.md#what-is-servlet)

spring.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- [What is the difference between @Resource and @Autowired annotations?](#what-is-the-difference-between-resource-and-autowired-annotations)
2525
- [What is the feature in Spring Boot for setting up the dependencies?](#what-is-the-feature-in-spring-boot-for-setting-up-the-dependencies)
2626
- [Where does Spring Boot application begin?](#where-does-spring-boot-application-begin)
27+
- [What is the difference between @Controller and @RestController annotations?](#what-is-the-difference-between-controller-and-restcontroller-annotations)
2728

2829
## How make spring service thread-safe?
2930
There are several ways, probably too long to list here but here are a few examples:
@@ -191,4 +192,11 @@ Spring Boot application begins from dependency to Spring Boot Starter.
191192
###### Relative links:
192193
- https://spring.io/guides/gs/spring-boot/
193194

195+
## What is the difference between @Controller and @RestController annotations?
196+
The job of @Controller is to create a Map of model object and find a view but @RestController simply return the object and object data is directly written into HTTP response as JSON or XML.
197+
198+
This can also be done with traditional @Controller and use @ResponseBody annotation but since this is the default behavior of RESTful Web services, Spring introduced @RestController which combined the behavior of @Controller and @ResponseBody together.
199+
###### Relative links:
200+
- https://javarevisited.blogspot.com/2017/08/difference-between-restcontroller-and-controller-annotations-spring-mvc-rest.html#ixzz61TUwViPi
201+
194202
[Home Page](README.md)

0 commit comments

Comments
 (0)