Springboot

Mapping 메서드 - get, post, put, delete

열곰탱 2022. 8. 29. 12:07

 

 white이름의 새로운프로젝트 생성

프로젝트가 하나이기 때문에 /를 작성한다.

만약 공유해야할 프로젝트가 여러개라면

server.servlet.context-path=/white 이런식으로 작성한다.

그럼 주소를 불러올때도 localhost:8000/white/user 이런식으로 불러온다.

 

 

 

 

Get 요청

 

 

 

 

 

 

 

chrom에도 요청이 가능하다.

 

Method 4가지 Get, Post, Put, Delete

 

Get,Post,Put,Delete

 

Get확인

 

Post확인

 

Put확인

 

Delete확인

 

 

전체코드

package site.metacoding.white;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

// Http Method -> Mapping 기술
// Get -> 주소창, 하이퍼링크
// POST, GET-> form 태그
// PUT, DELETE, GET, POST -> JS

// 포스트맨 -> 4가지 요청을 쉽게 테스트 해볼 수 있다.

@RestController //data를 응답
public class FirstController {
	
	
	
	
	@GetMapping("/first")
	public String getData() {
		return "<h1> data </h1>";
	}
	
	@PostMapping("/first")
	public String postData() {
		return "<h1>insert data</h1>";
	}
	
	@PutMapping("/first")
	public String putData() {
		return "<h1>update data</h1>";
	}
	@DeleteMapping("/first")
	public String DeleteData() {
		return "<h1>delete data</h1>";
	}
}