[Spring boot] thymeleaf

김나우·2021년 12월 23일
0

동작 환경 그림

참고

https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81-%EC%9E%85%EB%AC%B8-%EC%8A%A4%ED%94%84%EB%A7%81%EB%B6%80%ED%8A%B8

컨트롤러에서 리턴 값으로 문자를 봔한하면 뷰 리졸버(ViewResolve)가 화면을 찾아 처리한다.

  • 스프링 부트 템플릿엔진 기본 viewName 매핑
  • resources:templates/ + {ViewName} + .html

코드

@Controller
public class HelloController {

    @GetMapping("hello")
    public String hello(Model model){
        model.addAttribute("data","hello!!");
        return "hello";
    }

@Controller

Controller의 역할을 수행한다고 명시(해당 클래스를 Controller로 사용한다고 Spring FreameWork에 알린다

@GetMapping("hello")

웹 어플리케이션에서 /hello 라고 들어오면 아래에 있는 메서드를 호출

Model model

return "hello"

resources.templates에 있는 hello를 찾아서 Thymeleaf 템플릿 엔진 처리를 함

profile
안녕하세요

0개의 댓글