본문 바로가기
개발/Spring

[Java] IntelliJ+ Sptring boot + Maven + Thymeleaf + Mybatis +Oracle 프로젝트 시작하기(2)

by 코딩하는 흰둥이 2023. 3. 25.
반응형

이전 글

https://greed-yb.tistory.com/137

 

[Java] IntelliJ+ Sptring boot + Maven + Thymeleaf + Oracle 프로젝트 시작하기(1)

IntelliJ Ultimate 로 진행하였다 https://www.jetbrains.com/ko-kr/idea/download/#section=windows IntelliJ IDEA 다운로드: 우수성과 인체 공학이 담긴 JetBrains Java IDE www.jetbrains.com 프로젝트 생성하기 기본적으로 사용할 D

greed-yb.tistory.com

 

 

화면 페이지 생성하기

src -> main -> java -> com -> example -> demo 아래에 Controller 폴더를 생성하고 안에 java 파일을 만든다

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class MainController {

    @RequestMapping("/")
    public String main() throws Exception{
        return "index";
    }
}

메서드 명과 return 명이 같으면 오류가 날 수 있다 참고

 

resources -> templates 안에 html 파일을 만든다

파일명은 상관없으나 html 명과 controller에서 return 할 html 명은 항상 같아야 한다

 

우측 상단의 Run 을 실행하고 브라우저에서 locallhost:9090 을 입력하면 아래와 같이 연결이 된다

 

 

application.properties 설정 추가

#### thymeleaf
spring.thymeleaf.prefix=classpath:templates/
spring.thymeleaf.check-template-location=true
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.cache=false
spring.thymeleaf.order=0

# devtools
spring.devtools.livereload.enabled=true

thymeleaf를 사용하기 때문에 html 파일을 읽을 위치를 지정해준다

devtools는 화면의 코드를 수정하였을때 재실행 할 필요 없이 빌드만 해주면 수정한 코드로 바로바로 보여줘서 개발자의 편의를 위한 모듈이다 새로고침만 하면 수정한 내용을 확인 할 수 있다

 

 

 

 

댓글