컨트롤러 클래스 :
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWorldController
{
//using get method and hello-world as URI
// @GetMapping(path="/hello-world-bean")
@RequestMapping(method=RequestMethod.GET, value="/test")
public String sayHello()
{
return "Hello !!!";
}
@RequestMapping(method=RequestMethod.GET, value = "/getSquare/{number}")
public int getSquareOfNumber(@PathVariable int number)
{
return number*number;
}
}
애플리케이션 클래스 :
package com.firstService.server.main;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class RestfulWebServicesApplication {
public static void main(String[] args) {
SpringApplication.run(RestfulWebServicesApplication.class, args);
}
}
url http : // localhost / test (URL / hello에 대해 Hello를 표시 하고 있음)를 호출하려고 할 때 호출 되지 않고 오류 아래에 표시됩니다.