[spring] 입문 섹션 2

Minyoung kim·2022년 9월 23일
0

Spring

목록 보기
2/9

MVC 패턴

model(data 객체..?아직까진 모르겠다)
view(화면에 보여지는 부분)
controller(url과 view를 mapping하고 data를 client 측에서 전달받고 전송하는 등의 역할)

API 예제

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

@ResponseBody : helloApi함수에서 return hello를 해주었을 때, view에서 hello를 찾는 것이 아니라, 객체로서 반환하도록 해주는 역할
-> return hello를 하면, json 형태로 data가 전송된다
@RequestParam : "name"으로서 값을 전달받아서 name에 저장. url parameter로부터 값을 전달받기 위해서 사용됨.

0개의 댓글