resource/static/hello-static.html을 추가한 결과
스프링 컨트롤러가 파일을 찾아본 뒤 매핑이 된 컨텐츠가 없기 때문에 내부 resources안에 있는 html 파일을 찾는다.
모델: 내부적인 로직 처리
컨트롤러: 비지니스 로직 처리
뷰: 화면을 그리는 데에 집중
@ResponseBody: 뷰 리졸버를 사용하지 않고 http 바디에 문자를 그대로 전달
@GetMapping("hello-string")
@ResponseBody
public String helloString(@RequestParam("name") String name) {
return "hello "+name;
}
객체를 전달하는 경우: HttpMessageConverter가 동작, JsonConverter를 통해 JSON 형태로 변경
@GetMapping("hello-api")
@ResponseBody
public Hello helloAPi(@RequestParam("name") String name) {
Hello hello = new Hello();
hello.setName(name);
return hello;
}
static class Hello{
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}