Spring

@Controller @RestController 차이

코린이엄현종 2024. 3. 19. 18:13

 

@RestController

package com.eom.controllerexercise.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @RequestMapping(value = "/")
    public String hello() {
        return "hello";
    }
}

문자열 hello 를 반환

 

 


 

@Controller

package com.eom.controllerexercise.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Controller
public class HelloController {

    @RequestMapping(value = "/")
    public String hello() {
        return "hello";
    }
}

 

hello.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
  <h1>Hello Spring Boot!!</h1>
  <h6>This is Html Web Page</h6>
</body>
</html>

 

hello.html 을 반환한 모습