본문 바로가기
Spring

@Controller @RestController 차이

by 코린이엄현종 2024. 3. 19.

 

@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 을 반환한 모습

'Spring' 카테고리의 다른 글

Request 파라미터 실습  (0) 2024.03.20
RequestMapping과 URI 실습  (0) 2024.03.19
Spring Boot Application  (0) 2024.03.19
Spring Boot 실행 해보기  (0) 2024.03.18
Spring Boot 프로젝트 생성  (0) 2024.03.18