URL 매핑
http://localhost:8080/hello
라는 url에 "Hello, I'm ohgnoy"라는 문장을 출력하는 코드를 매핑했다.
package backend.ohgnoy;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class MainController {
@GetMapping("/hello")
public void index(){
System.out.println("Hello, I'm ohgnoy");
}
}
- 하지만 웹에 아무것도 리턴하지않아 에러가 걸린다.
- 아래를 보면 출력은 하지만 웹에서는 에러코드 500번이 뜬다.

package backend.ohgnoy;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MainController {
@GetMapping("/hello")
@ResponseBody
public String index(){
return "Hello, I'm ohgnoy";
}
}
