분류 전체보기 (277)

반응형

 

기본 페이지 설정

 

static 폴더 아래에 만들어야 실행할때의 기본 위치로 암.

 

 

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h1>만만세</h1>
</body>
</html>

 

결과 화면2 : static 폴더 안에 파일 생성 / 하단의 실행버튼으로 실행

 

 

 

Cotroller 파일 생성 및 실습

 

 

BaboController.java

package com.th.merorng.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController //@Controller + @RestController 기능을 함
@RequestMapping("/babo")
public class BaboController {
	
	@GetMapping("/pc")
	public String getBabo() {
		return "피씨바보";
	}
}

 

결과 화면2 : url 입력 시 /babo/pc 를 추가해야함

 

 

 

fetch 사용 방법

 

 

  • 1번 방법 : fetch then

BaboController.java

package com.th.merorng.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController //@Controller + @RestController 기능을 함
@RequestMapping("/babo")
public class BaboController {
	
	@GetMapping("/pc")
	public String getBabo() {
		return "피씨바보";
	}
}

 

 

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>만만세</h1>
<button id="pcBtn">피씨는?</button>

<script>
	//스크립트 자동완성 됨 (Ctrl + 스페이스로 자바스크립트 타입으로 변경해줘야함)
	const pcBtn = document.querySelector("#pcBtn");
	pcBtn.onclick = function(){
		fetch("/babo/pc").then((resp)=>{ //프라미스 타입으로 반환되기에 then를 사용할 수 있음
			//text 말고 json, blob 사용할 수 있음
			resp.text().then((retVal)=>{  //기본적으로 fetch를 사용할 경우 then을 두 번 씀
				alert("최종 서버가 돌려준 값: " + retVal);
			});
		});
	}
</script>
</body>
</html>

 

결과 화면3-1

 

결과 화면3-2

 

 

 

  • 2번 방법 : async await

BaboController.java

1번 방법과 같은 컨트롤러 내용

 

 

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>만만세</h1>
<button id="pcBtn">피씨는?</button>

<script>
	//스크립트 자동완성 됨 (Ctrl + 스페이스로 자바스크립트 타입으로 변경해줘야함)
	const pcBtn = document.querySelector("#pcBtn");
	
	//async/await 세트를 잘 쓰면 Promise에 대응하는 가독성이 높아짐
	async function fetchData() {
		let resp = await fetch("/babo/pc"); //promise이기에 then 대신 await를 사용할 수 있음
		let retVal = await resp.text(); //await를 사용하기 위해선 async 함수여야함
		alert("보기 좋은가? " + retVal); //아래와 같이 함수를 하나 필수로 만들어야함
	}
	
	pcBtn.onclick = function(){
		fetchData();
	}
	
</script>
</body>
</html>

 

결과 화면4-1

 

결과 화면4-2

 

 

반응형
반응형

 

설정

 

1

 

1. Exclude 선택 > Proceed 클릭

 

 

2

 

2. New > Spring Starter project 클릭

 

 

3

 

3. 입력 후 Next 클릭

 

 

4

 

4. 검색 후 체크박스 클릭 > 오른쪽에 추가된 것 확인 > 2개 추가 확인 후 Next 클릭

+ Spring Boot Actuator 도 추가로 검색하여 추가하는 것도 좋음

 

 

5

 

5. 링크 확인 > Finish 클릭

 

 

 

인코딩 설정

 

 

1

 

1. Window > Preferences 클릭

 

 

2

 

2. enc 검색 > Text 파일의 인코딩을 UTF-8로 변경 > Update 클릭

Java Properties File, Spring Properties File 도 인코딩 UTR-8로 변경

왼쪽 탭의 Workspace 도 UTF-8로 설정되었는지 확인

 

 

3

 

3. Web Browser 클릭 > Chrome 클릭 > Apply and Close 클릭

 

 

 

실행 방법

 

 

1

 

1. 프로젝트 오른쪽 마우스 클릭 > Run As > Spring Boot App 클릭

 

 

2

 

2. 8004로 실행된 것 확인

 

 

 

포트 번호 설정

 

1

 

1. application.properties 클릭 > server.port=8004 입력 후 저장

 

 

 

html 파일 만들 수 있게 설정

 

1

 

1. Help > Eclipse Marketplace 클릭

 

 

2

 

2. jsp 검색 > Install 클릭 > 쭉 진행

 

 

3

 

3. Select All 클릭 > Restart 

 

 

4

 

4. Window > Preferences 클릭

 

 

5

 

5. enc 검색 > Web과 XML의 인코딩 UTF-8인지 확인 및 변경 > Apply and Close 클릭

 

 

6

 

6. New > Other 클릭

 

 

7

 

7. html 검색 > 파일이 잘 뜨는지 확인

 

 

 

반응형
반응형

 

spring boot 설치

 

 

 

아래의 링크를 통해 들어감

 

https://start.spring.io/

 

1

 

1. 해당 여부 클릭 > ADD DEPENDENCIE 클릭

 

 

2

 

2. Web 검색 > 클릭 > ADD DEPENDENCIE 클릭 > lombok 검색 > 클릭

 

 

3. 추가된 것 확인 > GENERATE 클릭 > 다운로드 됨

 

 

 

 

amazon corretto, sts4 설치

 

 

1

 

1. Amazon Corretto 페이지 들어감 > Corretto 21 다운로드

 

2

 

2. 파일 다운로드

 

3

 

3. 하단의 링크 클릭 > 파일 다운로드

 

아마존에서 다운로드 받은 Corrotto21 를 사용하기 위해서 sts4를 사용해야함

 

 

https://github.com/spring-projects/sts4/wiki/Previous-Versions

 

Previous Versions

The next generation of tooling for Spring Boot, including support for Cloud Foundry manifest files, Concourse CI pipeline definitions, BOSH deployment manifests, and more... - Available for Eclipse...

github.com

 

 

4

 

4. 2와 3에서 다운로드 받은 파일을 한 폴더에 풀기

 

5, 6

 

5. 압축 푼 위치에서 .ini 파일 복사 > 복사한 파일 뒤에 _ 추가로 백업본 생성

 

6. .ini 파일 열기

 

7

 

7. jdk 설치 폴더에서 bin 폴더로 이동 > 링크 복사 > .ini 파일의 vm에 수정 > 뒤에 \javaw.exe 추가

 

8

 

8. exe 파일 클릭하여 실행

 

 

 

jar와 war 파일 차이점

 

  • jar (java archive) -> 

- 장점
JVM에서 직접 실행 > 별도의 웹 컨테이너나 서버 필요하지 않음.

- 단점
JSP나 서블릿 컨테이너 표준 기능 활용 어려움

 

=> desktop application

 

 

 

  • war (web archive)

- 장점
한 번에 배포 및 실행 가능
다양한 웹 기능과 서버 환경 활용 가능

- 단점
특정한 웹 컨테이너 환경이 필요

 

 

 

  • ear (enterprise archive) 

잘 사용하지 않음

 

 

반응형
1 2 3 4 5 6 7 8 ··· 93