스프링 부트2 (view 환경설정)

2024. 6. 21. 13:50·Springboot

스프링 부트에서는 welcome page를 지원하는데 처음으로 index.html 파일을 찾는다.

 

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Hello</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<p th:text="'안녕하세요. '+${data}">안녕하세요 손님</p>
</body>
</html>

 

package hello.first_spring.controller;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class HelloController {

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

 

템플릿 엔진의 동작과정

1. 브라우저에서 localhost8080/hello url을 요청한다.

2. 내장 톰캣 서버에서 컨트롤러에 데이터 전달 

3. GetMapping 어노테이션을 통하여 hello를 실행

4. 스프링 부트에서 자체적으로 model을 만들어주고 data 키에 hello를 저장

5. hello 리턴하면 뷰 리졸버가 화면을 찾아서 처리

- 스프링 부트 템플릿엔진 기본 viewName 매핑

- 'resources:templates/'+{ViewName }+'.html'

 

'Springboot' 카테고리의 다른 글

[스프링 부트] 페이지네이션 정보 응답 받기  (0) 2024.07.01
[스프링 부트] Entity 매핑 무한루프  (0) 2024.07.01
[스프링 부트] DispatcherSevlet의 역할  (0) 2024.06.29
[스프링 부트] Object Mapper  (0) 2024.06.25
스프링 부트1 (시작)  (0) 2024.06.21
'Springboot' 카테고리의 다른 글
  • [스프링 부트] Entity 매핑 무한루프
  • [스프링 부트] DispatcherSevlet의 역할
  • [스프링 부트] Object Mapper
  • 스프링 부트1 (시작)
코딩 못하는 감자
코딩 못하는 감자
  • 코딩 못하는 감자
    코딩 못하는 감자의 기록
    코딩 못하는 감자
  • 전체
    오늘
    어제
    • 분류 전체보기 (91)
      • Kubernetes (10)
      • Github Action (1)
      • Docker, Container (3)
      • Springboot (26)
      • Baekjoon (4)
      • 명품 운영체제 (9)
      • 데이터베이스 (2)
      • JSP (3)
      • 안드로이드프로그래밍 (1)
      • 미니프로젝트 (1)
      • 용어정리 (0)
      • 소프트웨어공학 (3)
      • 운영체제 (2)
      • Flutter (0)
      • Git (1)
      • HTTP (0)
      • RAG (1)
      • Database (2)
      • FastAPI (1)
      • Elasticsearch (7)
      • Redis (0)
      • JPA (5)
      • Linux (1)
      • MCP (1)
  • 블로그 메뉴

    • 홈
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    엘라스틱서치 인덱스
    fuzziness
    mcp #model context protocol #claude desktop #mcp claude연동 #claude 파일 시스템 연동
    엘라스틱서치 인덱스 복사
    응답 로그
    SpringBoot
    elasticsearch ngram
    elasticsearch 커스텀분석기
    Dockerfile
    elasticsearch analyzer
  • hELLO· Designed By정상우.v4.10.3
코딩 못하는 감자
스프링 부트2 (view 환경설정)
상단으로

티스토리툴바