-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
115 additions
and
0 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
springmvc/src/main/java/hello/springmvc/basic/requestmapping/MappingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package hello.springmvc.basic.requestmapping; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
public class MappingController { | ||
|
||
private Logger log = LoggerFactory.getLogger(getClass()); | ||
|
||
@RequestMapping(value = "/hello-basic", method = RequestMethod.GET) | ||
public String helloBasic() { | ||
log.info("helloBasic"); | ||
return "ok"; | ||
} | ||
|
||
/** | ||
* method 특정 HTTP 메서드 요청만 허용 | ||
* GET, HEAD, POST, PUT, PATCH, DELETE | ||
*/ | ||
@RequestMapping(value = "/mapping-get-v1", method = RequestMethod.GET) | ||
public String mappingGetV1() { | ||
log.info("mappingGetV1"); | ||
return "ok"; | ||
} | ||
|
||
/** | ||
* 편리한 축약 애노테이션 (코드보기) | ||
* @GetMapping | ||
* @PostMapping | ||
* @PutMapping | ||
* @DeleteMapping | ||
* @PatchMapping | ||
*/ | ||
@GetMapping(value = "/mapping-get-v2") | ||
public String mappingGetV2() { | ||
log.info("mapping-get-v2"); | ||
return "ok"; | ||
} | ||
|
||
/** | ||
* PathVariable 사용 | ||
* 변수명이 같으면 생략 가능 | ||
* @PathVariable("userId") String userId -> @PathVariable userId | ||
*/ | ||
@GetMapping("/mapping/{userId}") | ||
public String mappingPath(@PathVariable("userId") String data) { | ||
log.info("mappingPath userId={}", data); | ||
return "ok"; | ||
} | ||
|
||
/** | ||
* PathVariable 사용 다중 | ||
*/ | ||
@GetMapping("/mapping/users/{userId}/orders/{orderId}") | ||
public String mappingPath(@PathVariable String userId, @PathVariable Long orderId) { | ||
log.info("mappingPath userId={}, orderId={}", userId, orderId); | ||
return "ok"; | ||
} | ||
|
||
/** | ||
* 파라미터로 추가 매핑 | ||
* params="mode", | ||
* params="!mode" | ||
* params="mode=debug" | ||
* params="mode!=debug" (! = ) | ||
* params = {"mode=debug","data=good"} | ||
*/ | ||
@GetMapping(value = "/mapping-param", params = "mode=debug") | ||
public String mappingParam() { | ||
log.info("mappingParam"); | ||
return "ok"; | ||
} | ||
|
||
/** | ||
* 특정 헤더로 추가 매핑 | ||
* headers="mode", | ||
* headers="!mode" | ||
* headers="mode=debug" | ||
* headers="mode!=debug" (! = ) | ||
*/ | ||
@GetMapping(value = "/mapping-header", headers = "mode=debug") | ||
public String mappingHeader() { | ||
log.info("mappingHeader"); | ||
return "ok"; | ||
} | ||
|
||
/** | ||
* Content-Type 헤더 기반 추가 매핑 Media Type | ||
* consumes="application/json" | ||
* consumes="!application/json" | ||
* consumes="application/*" | ||
* consumes="*\/*" | ||
* MediaType.APPLICATION_JSON_VALUE | ||
*/ | ||
@PostMapping(value = "/mapping-consume", consumes = "application/json") | ||
public String mappingConsumes() { | ||
log.info("mappingConsumes"); | ||
return "ok"; | ||
} | ||
|
||
/** | ||
* Accept 헤더 기반 Media Type | ||
* produces = "text/html" | ||
* produces = "!text/html" | ||
* produces = "text/*" | ||
* produces = "*\/*" | ||
*/ | ||
@PostMapping(value = "/mapping-produce", produces = "text/html") | ||
public String mappingProduces() { | ||
log.info("mappingProduces"); | ||
return "ok"; | ||
} | ||
} |