Notice
Recent Posts
Recent Comments
Link
«   2024/10   »
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 29 30 31
Archives
Today
Total
관리 메뉴

한바다

@RequestMapping 과 @GetMapping 본문

servlet

@RequestMapping 과 @GetMapping

한바다진화 2024. 6. 11. 21:50

@RequestMapping

  • 기능: 다양한 HTTP 메서드(GET, POST, PUT, DELETE 등)에 대해 사용 가능.
  • 속성: method 속성을 사용해 특정 HTTP 메서드를 지정할 수 있음.
  • @RequestMapping 을 쓰면 기본으로 return할 때 html 파일을 바라보겠다
  •  classpath : src/main/resource
    기본경로에 앞에 붙여진 /templates/ 폴더가 html을 담는 공간
    파일명 마지막에는 항상 .html 이 붙는다.

[코드]

import org.springframework.stereotype.Controller;

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

 

@Controller

public class IndexController {

@RequestMapping("test")

public String 테스트페이지연결메서드() {

return "test";

   }

}

 

@GetMapping

  • 기능: GET 요청 전용으로 사용.
  • 편리성: @GetMapping 의 간편한 버전으로, 코드가 더 간결해짐
  • @GetMapping  을 쓰면 기본으로 return할 때 html 파일을 바라보겠다
  •  classpath : src/main/resource
    기본경로에 앞에 붙여진 /templates/ 폴더가 html을 담는 공간
    파일명 마지막에는 항상 .html 이 붙는다.

@RequestMapping: 다양한 HTTP 메서드를 처리할 수 있음.

@GetMapping: GET 요청을 간단하게 처리할 수 있음.

 

[코드]

import org.springframework.stereotype.Controller;

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

@Controller

public class ExampleController {

@GetMapping("example")

public String 이그잼플메서드() {

return "example";

     }

}

 

[이클립스>깃허브 하는 방법]

상단메뉴 윈도우>쇼뷰>아덜