

위와 같이 설정후에 다운로드 받은 zip 파일을
작업할 폴더로 옮겨주고 압축해제해준다

인텔리제이로 돌아와서 아래와 같이 실행

아래사진과 같이 src - java - hellov1 생성되어있고
c 부분에 파란색으로 되야지만 제대로 설정된 것이다

-gead : 설정파일
- src-main-java : java 안에는 자바파일만 들어간다
- src- main - resources : 자바 외 모든 파일


주소창에 localhost:8080 입력하면
아래와 같이 뜬다



@Controller 누르면
import 생성
* ctrl + shift + enter



회색 부분은 입력 안 해도 자동완성된다
- 템플릿폴더의 html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>hello</title>
</head>
<body>
<p th:text="'반갑습니다, ' + ${data} +'님' ">반갑습니다</p>
<!--th 는 타임리프 , 타임리프를 입력해야지 데이터를 받을 수 있따-->
</body>
</html>
- static 폴더의 index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>hello</title>
</head>
<body>
hello<a href="/hello">hello</a>
</body>
</html>
- controller 폴더의 HelloController.java
package hellov2.hellov2_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","윤수명");
return "hello";
}
}
정적 컨텐츠에서 정적 컨텐츠로 이동하기
둘 다 static에 만들어서 링크만 연결한다


hellocontroller.java
package hellov2.hellov2_spring.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 {
@GetMapping("hello")
public String hello(Model model) {
model.addAttribute("data","윤수명");
return "hello";
}
@GetMapping("/helloMvc")
public String hellowMvc(@RequestParam("name") String name1, Model model){
model.addAttribute("name",name1);
return "hello-mvc";
}
}
- hello-mvc
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>hello-mvc</title>
</head>
<body>
<p th:text="'hello! ' + ${name}">hello! empty</p>
</body>
</html>
- hello-static
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>hello-static</title>
</head>
<body>
<hr>
<a href="/">home으로 이동</a>
<p>정적 컨텐츠</p>
</body>
</html>
- index
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>hello</title>
</head>
<body>
hello<a href="/hello">hello</a>
<hr>
<a href="/helloMvc">Param데이터</a>
<a href="/hello-static.html">정적 컨텐츠</a>
</body>
</html>
?name=name1
?name=spring


-

'spring' 카테고리의 다른 글
| spring_login-spring (0) | 2024.11.01 |
|---|---|
| spring_IntellJ 트리식 구조로 프로젝트 패키지 보기 (0) | 2024.10.31 |
| spring_인텔리제이에서 부트스트랩 적용하기 (0) | 2024.10.31 |
| spring_home (0) | 2024.10.30 |
| spring_h2 (0) | 2024.10.30 |