카테고리 없음

spring boot 공식 예제 오류 수정

Sumin Lim 2025. 5. 20. 10:39
반응형

10년만에 돌려봄 ㅋ 근데 공식사이트에서 하라는데로 하는데 왜 ㅋㅋㅋ 에러가 있는지

@RestController 를 빠진채로 안내하다니..


package cohttp://m.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController   // ← 이걸 추가!
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @GetMapping("/hello")
    public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
        return String.format("Hello %s!", name);
    }
}

반응형