ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Spring] 프로젝트 환경설정
    카테고리 없음 2024. 9. 25. 23:43
    • Controller에서 return값으로 문자 ({ViewName})를 반환하면 viewResolver가 화면을 찾아서 처리한다.
      • `resources:templates/` + {ViewName} + `.html`
    hello/hellospring/controller/HelloController.java
    package hello.hellospring.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", "✨Spring💚");
            return "hello";
        }
    }

     

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

     

     

    프로젝트 구조

     

    HelloSpringApplication 실행

Designed by Tistory.