728x90
@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";
}
@GetMapping(value = "/mapping-get-v2")
public String mappingGetV2(){
log.info("mapping-get-v2");
return "ok";
}
@GetMapping("/mapping/{userId}")
public String mappingPath(@PathVariable("userId") String data){
log.info("mappingPaht userId={}",data);
return "ok";
}
@GetMapping("/mapping/users/{userId}/orders/{orderId}")
public String mappingParam(@PathVariable String userId, @PathVariable String 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 mappingParam2(){
log.info("mapping param");
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-product", produces = "text/html")
public String mappingProduces() {
log.info("mappingProduces");
return "ok";
}
}
728x90
'백엔드 > Spring(Boot)' 카테고리의 다른 글
스프링 HTTP 헤더 조회 (0) | 2021.09.09 |
---|---|
스프링 API 개발 기초 (0) | 2021.09.09 |
로깅 (0) | 2021.09.08 |
JPA 페이징 (0) | 2021.09.03 |
프로젝션 - 여러 값 조회 (0) | 2021.09.03 |