Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Python
- 단기개발자코스
- 항해99
- DesignPattern
- 코딩테스트 준비
- Spring multimodule
- 프로그래머스
- infcon 2024
- 전략패턴 #StrategyPattern #디자인패턴
- jwt
- jwttoken
- JavaScript
- 디자인 패턴
- TiL
- 99클럽
- 프로그래머스 이중우선순위큐
- KPT회고
- 구글 OAuth login
- 1주일회고
- 디자인패턴
- 인프콘 2024
- 개발자 취업
- @FeignClient
- 개발자부트캠프추천
- spring batch 5.0
- 취업리부트코스
- 빈 충돌
- 파이썬
- 빈 조회 2개 이상
- 커스텀 헤더
Archives
- Today
- Total
m1ndy5's coding blog
View로 서버 잘 돌아가는지 확인하기 본문
/src/main/resources/static에 index.html파일을 만들면 서버를 실행했을 때 index.html에 들어가 있는 내용들이 나온다.
https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/spring-boot-features.html#boot-features-webflux-welcome-page
It first looks for an index.html file in the configured static content locations. -> static에서 index.html을 먼저 찾는다.
메뉴얼에서 검색하는 방법을 알아두면 좋다.
/hello.hellospring/controller/HelloController
@Controller //컨트롤러 어노테이션을 붙어야 컨트롤러라고 인식이됨
public class HelloController {
@GetMapping("hello") //hello라는 경로로 들어오게 되면
public String hello(Model model){
model.addAttribute("data", "hello!!"); //data라는 모델에 hello라는 값을 집어넣음
return "hello"; //hello라는 템플릿을 찾음
}
}
/resources/templates/hello.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="'안녕하세요. ' + ${data}" >안녕하세요. 손님</p> //data에 저장된 값이 출력됨
</body>
</html>
- 컨트롤러에서 리턴값으로 문자를 반환하면(ex. hello) viewResolver가 화면을 찾아서 처리
- resources/templates/{ViewName(ex. hello)}+.html 로 찾아줌
실행하기
Intellij에서 run
@SpringBootApplication 어노테이션이 붙은 클래스를 run해주면 된다.
console에서 build
프로젝트 파일까지 들어간 후 아래의 방법을 따르면 된다.
For Linux
- ./gradlew build
For Window
- gradlew build
공통
2. cd build/libs
3. java -jar hello-spring-0.0.1-SNAPSHOT.jar
4. 실행 확인
실행시킬 때 가장 중요한 것!! 같은 포트에 서버 2개 못띄우기 때문에 이전 서버를 종료시켜줄 것!
만약 8080에 돌아가고 있어서 못한다면 ps -ef 에서 pid확인 후 kill -9 pid해서 죽여버리자!!ㅎㅎ
'백엔드 with java > spring' 카테고리의 다른 글
Spring Security UserDetails, UserDetailsService (1) | 2023.10.11 |
---|---|
Jackson & Constructor (0) | 2023.07.11 |
정적 컨텐츠 VS MVC와 템플릿엔진 VS API (0) | 2023.03.07 |
Spring Libraries (간단하게) (0) | 2023.03.07 |
Springboot 프로젝트 생성 (0) | 2023.03.07 |