프레임워크/Spring, Spring Boot

[메타코딩] 스프링부트 강좌 13강(블로그 프로젝트) - http요청 실습1

고용인 2022. 7. 25. 12:36

- Controller를 생성합니다.

package com.cos.blog.test;

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;

// 사용자가 요청 -> 응답(HTML 파일)
// @Controller

// 사용자가 요청 -> 응답(Data)
@RestController
public class HttpControllerTest {

	// http://localhost:8080/http/get
	@GetMapping("/http/get")
	public String getTest() {
		return "get 요청" ;
	}
	
	// http://localhost:8080/http/post
	@PostMapping("/http/post")
	public String postTest() {
		return "post 요청";
	}
	
	// http://localhost:8080/http/put
	@PutMapping("/http/put")
	public String putTest() {
		return "put 요청";
	}
	
	// http://localhost:8080/http/delete
	@DeleteMapping("/http/delete")
	public String deleteTest() {
		return "delete  요청";
	}
}

get 요청
post 요청
put 요청
delete 요청

* 브라우저에서는 get요청만 보낼 수 있습니다. post, put, delete 요청시 405에러가 발생합니다.

 

 

 

강의 주소 : https://youtu.be/BNiDNAWZn-E