on
[Spring] Controller에 GetMapping 이용하여 페이지 호출
[Spring] Controller에 GetMapping 이용하여 페이지 호출
localhost:8080 호출 시, 매핑정보가 없으면 resources/static/index.html 이 호출됨.
SITE html example hello world
1. Controller 생성
java/com/example/demo/Hello/HelloController.java
package com.example.demo.Hello; 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"; } }
resources/templates/hello.html 반환
* model.addAttribute( [attributeName], [attributeValue] )
[attributeName] 와 매핑 시킬 resources/templates/hello.html 의 변수값을 동일하게 해야 값이 제대로 전달됨
Hello 안녕하세요. 손님
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/dashboard
from http://yon2ive.tistory.com/45 by ccl(A) rewrite - 2021-12-20 12:27:33