컨트롤러
package hello.hellospring.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class HelloController {
// /hello 로 get 주소 입력시 아래 소스 매핑하라는 명령어
@GetMapping("hello")
public String hello(Model model){
model.addAttribute("data","hello!!"); //모델에 정보담아서 세팅
return "hello"; //hello.html로 model 데이터 전달 명령어
}
@GetMapping("hello-mvc")
public String helloMvc(@RequestParam("name") String name, Model model){
model.addAttribute("name",name);
return "hello-template";
}
}
@GetMapping("hello-mvc")
public String helloMvc(@RequestParam("name") String name, Model model){
model.addAttribute("name",name);
return "hello-template";
}
웹에 http://localhost:8080/hello-mvc?name=ssee22 url 접근시 hello-template로 값 넘겨줌
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="'hello '+${name}">안녕하세요. empty</p>
</body>
</html>
'개발 > spring' 카테고리의 다른 글
window intelij 겟터 셋터 자동 만들기 getter and setter auto make (0) | 2022.11.25 |
---|---|
spring api 데이터 받기 (0) | 2022.11.24 |
빌드하고 실행하기 (0) | 2022.11.24 |
spring view 환경설정 (0) | 2022.11.24 |
스프링 라이브러리 살펴보기 톰켓 설치없이 바로 locallhost에 소스를 띄울 수 있는 이유에 대하여 (0) | 2022.11.24 |
댓글