728x90
project name: demo
처음 자동 생성되는 (*Project name)Applicaton.java (DemoApplication.java) 파일의 클래스(DemoApplication)에 @RestController 어노테이션 붙이고 @GetMapping
package com.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);
}
}
새로 생성한 클래스에 @Controller 어노테이션 붙이고 @GetMapping + @ResponseBody
ERROR>>
@Controller 안붙이고 썼더니 계속 404 에러 ㅠㅠ
Whitelabel Error PageThis application has no explicit mapping for /error, so you are seeing this as a fallback.Mon Apr 10 03:30:33 KST 2023
There was an unexpected error (type=Not Found, status=404).
|
728x90