API 작성하기

@GetMapping("hello-string")
@ResponseBody
public String helloString(@RequestParam("name")String name){
	return "hello " + name;
}

객체를 리턴하는 방법

static class Hello{ // 예시를 위해 정적 클래스 선언
	private String name;
	public getName(){
		return this.name;	
	}
	public setName(String name){
		this.name = name;
	}
}

@GetMapping("hello-api")
@ResponseBody
public helloApi(@RequestParam("name") String name){
	Hello hello = new Hello();
	hello.setName("leejaebeen");
	return hello;
}

json형식으로 객체 hello( “name”:”leejaebeen” )가 리턴됨을 확인할 수 있다.

Response Body의 원리

Untitled

일반적인 웹 어플리케이션 구조

domain