-
인프런 스프링 입문 02 / 간단한 실행스프링&스프링부트 2022. 12. 1. 22:58
스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술
프로젝트 환경설정
2. 라이브러리 살펴보기
톰캣 설치 안 하고 바로 연결된다니...
마지막 프로젝트 진행하면서 서버 때문에 오류도 가끔 나고 불편했었는데...
국비 교육이 옛날 기술을 쓴다는 점은 알고 있었지만 인강을 보면 볼수록 띵하다...
이래서 개발자는 계속해서 공부해야 하나 보다
3. View 환경설정
1) src > main > resourcese > static 폴더 >> (new > file > index.html)
2) index 페이지 코드 작성 > 서버 껐다 켜기 > http://localhost:8080/
<!DOCTYPE HTML> <html> <head> <title>Hello</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> Hello <a href="/hello">hello</a> </body> </html>
@Controller public class HelloController { @GetMapping("hello") public String hello(Model model) { model.addAttribute("data", "hello!!"); return "hello"; } }
<!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>
- 컨트롤러에서 리턴 값으로 문자를 반환하면 뷰 리졸버(ViewResolver)가 화면을 찾아서 처리한다.
> 스프링 부트 템플릿엔진 기본 viewName 매핑
> resources:templates/ + {ViewName} + .html
* 참고 : spring-boot-devtools 라이브러리 추가하면, html 파일을 컴파일만 해주면 서버 재시작 없이 View 파일 변경이 가능하다.
4. 빌드하고 실행하기
- 제공된 자료를 보면서 윈도우 gradle build하려고 하니까 오류가 발생했고 해결했다
인텔리제이 윈도우 gradle build하는 방법, gradlew build 오류 해결 방법
나와 같이 정말 하나도 모르는 사람들을 위해 자세히 써 보자면 cmd 창을 먼저 켜고 1. cd + gradle이 있는 파일 주소를 넣는다 예) cd C:\Users\USER\Desktop\study\hello-spring 2. gradlew build 엔터를 누르면 원래
gitofjy.tistory.com
728x90'스프링&스프링부트' 카테고리의 다른 글
JSON이란? JSON 기초 정리 (1) 2022.12.03 인프런 스프링 입문 03 / 정적 콘텐츠, MVC (0) 2022.12.02 인텔리제이 윈도우 gradle build하는 방법, gradlew build 오류 해결 방법 (1) 2022.12.01 인프런 스프링 입문 01 / 인텔리제이 설치, 스프링부트 localhost 로그인, 인텔리제이 윈도우 preference (0) 2022.11.29 intelliJ community 설치, 학생 라이센스 인증 방법, 졸업 후 학생 인증 (0) 2022.11.29