스프링부트에 대한 개념 공부가 부족하다고 생각되어서 동아리 스터디로 김영한의 <스프링 입문-코드로 배우는 스프링 부트, 웹, MVC, DB 접근 기술> 강의를 수강하게 되었다.
빌드 자동화 도구는 Gradle을 사용하였다. 이는 의존성을 알아서 관리해주고, build.gradle에 스크립트를 작성하고 대규모 프로젝트에서 복잡해지는 경향이 있는 XML 기반 스크립트에 비해 관리가 편리하다는 장점이 있다. Maven에서 발전된 것이라고 보면 된다.

@Controller
public class HelloController{
@GetMapping("hello")
public String Hello(Model model){
model.addAttribute("data","hello!");
return "hello"; //resources/templates/hello.html 로 렌더링
hello-static.html 그대로 웹 브라우저에 반환 MVC : Model, View, Controller
@Controller
public class HelloController{
@GetMapping("helloMvc")
public String helloMvc(@RequestParam("name") String name, Model model){
model.addAttribute("name",name);
return "hello-template";
}
}
resoureces/templates/hello-template.html
웹 브라우저에서 요청이 내장 톰캣 서버로 가게 되면 그 요청이 helloController로 던져진다. 그리고 model안에 name value 값을 가지고 viewResolver로 간다. 여기서 타임 리프 템플릿 엔진 처리를 한 후 웹 브라우저에 다시 보여질 때는 HTML을 변환 후에 화면에 보여지게 된다.
@Controller
public class HelloController{
@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; //외부에서 접근 X
//getter,setter같은 메서드들을 통해서 외부에서 접근할 수 있도록
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
}
}
✍️ 대부분 JSON 을 가장 많이 사용하기는 함 !!