기본적인 경로 지정

@Controller
@ResponseBody
@RequestMapping(
	value="hello"
)
public class SampleController{
	// GET : hello/
	@GetMapping()
	public void HelloWorld(){
		return "Hello World";
	}
}

파라미터, 쿼리, body값 가져오기

@Controller
@ResponseBody
@RequestMapping(
	value="hello"
)
public class SampleController{
	// GET : hello/
	@GetMapping()
	public String HelloWorld(){
		return "Hello World";
	}
	
	/* 파라미터 가져오기 */
	// GET : hello/{id}
	@GetMapping("{id}") // 이처럼 경로만 필요하면 value를 생략 가능
	public int ReteurnParam(
		@PathVariable("id") int id
	){
		//id는 hello/{id}의 id 값을 받아주게 된다.
		return id;
	}
	
	/* 쿼리값 가져오기 */
	// GET : hello/query?id=id
	@GetMapping("query")
	public int ReturnQuery(
		@RequestParam("id") int id
	){
		return id;
	}

	/* request의 body 가져오기 */
	// GET : hello/body
	@GetMapping("body")
	public PostData ReturnBody(
		@RequestBody PostData postData 
	){
		return postData;
	}
	
	/* image 읽어오기 */
	// produces : MediaType.IMAGE_PNG_VALUE이므로 png 타입의 이미지를 응답으로 반환
	// GET : hello/sample-image
	@GetMapping(
    value = "/sample-image",
    produces = MediaType.IMAGE_PNG_VALUE
  )
  public byte[] sampleIamge() throws IOException{ //image는 byte[]를 반환함.
    //resoures 폴더에서 name에 해당하는 파일을 읽어옴.
    InputStream inputStream = getClass().getResourceAsStream("/static/img.png");
    return inputStream.readAllBytes();
  }
}

RestController

Model에 데이터 담아서 보내기