Post

Mapping

Mapping

기존 project에서 내가 원래 작성했던 코드랑 달라 궁금증이 생겨서 찾아보게 되었다.

그리고 코드를 변경하게 되었다.😄



Mapping

기존

1
2
3
4
5
6
7
8
9
10
11
@RequestMapping(value = "/test", method = RequestMethod.POST)
public String postTest() {}

@RequestMapping(value = "/test", method = RequestMethod.GET)
public String getTest() {}

@RequestMapping(value = "/test", method = RequestMethod.PUT)
public String putTest() {}

@RequestMapping(value = "/test", method = RequestMethod.DELETE)
public String deleteTest() {}

⬇️

1
2
3
4
5
6
7
8
9
10
11
@PostMapping()
public String postTest() {}

@GetMapping()
public String getTest() {}

@PutMapping()
public String putTest() {}

@DeleteMapping()
public String deleteTest() {}

간단하게 작성된 것을 볼 수 있다.



@RequestMapping에서 옵션을 넣어주는 경우에는 url 앞에 value를 붙여야 한다.

*옵션이 value 하나인 경우에는 url만 작성

이렇게 작성할 경우 코드가 길어지니깐 아래와 같이 작성하는 것이다.

  • @PostMapping
  • @GetMapping
  • @PutMapping
  • @DeleteMapping
  • @PatchMapping
This post is licensed under CC BY 4.0 by the author.