Copy @ RestController
public class MappingController {
private Logger log = LoggerFactory . getLogger ( getClass() );
@ RequestMapping ( "/hello-basic" )
public String helloBasic () {
log . info ( "helloBasic" );
return "ok" ;
}
}
Copy @ RestController
public class MappingController {
private Logger log = LoggerFactory . getLogger ( getClass() );
@ RequestMapping (value = "/mapping-get-v1" , method = RequestMethod . GET )
public String mappingGetV1 () {
log . info ( "mappingGetV1" );
return "ok" ;
}
@ GetMapping (value = "/mapping-get-v2" )
public String mappingGetV2 () {
log . info ( "mapping-get-v2" );
return "ok" ;
}
}
Copy @ RestController
public class MappingController {
private Logger log = LoggerFactory . getLogger ( getClass() );
/*
* /mapping/userA 이런 식으로 경로 자체에 값이 있는 것
* */
@ GetMapping ( "/mapping/{userId}" )
public String mappingPath (@ PathVariable ( "userId" ) String data) {
log . info ( "mappingPath userId={}" , data);
return "ok" ;
}
/* 변수명이 같으면 생략 가능하다. */
@ GetMapping ( "/mapping/{userId}" )
public String mappingPath2 (@ PathVariable String userId) {
log . info ( "mappingPath userId={}" , userId);
return "ok" ;
}
}
Copy @ RestController
public class MappingController {
private Logger log = LoggerFactory . getLogger ( getClass() );
@ GetMapping ( "/mapping/users/{userId}/orders/{orderId}" )
public String mappingPath (@ PathVariable String userId , @ PathVariable Long orderId) {
log . info ( "mappingPath userId={}, orderId={}" , userId , orderId);
return "ok" ;
}
}
Copy @ RestController
public class MappingController {
private Logger log = LoggerFactory . getLogger ( getClass() );
/**
* 파라미터로 추가 매핑
* 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" ;
}
}
Copy @ RestController
public class MappingController {
private Logger log = LoggerFactory . getLogger ( getClass() );
/**
* 특정 헤더로 추가 매핑
* 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" ;
}
}
Copy @ RestController
public class MappingController {
private Logger log = LoggerFactory . getLogger ( getClass() );
/**
* 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" ;
}
}
Copy @ RestController
public class MappingController {
private Logger log = LoggerFactory . getLogger ( getClass() );
/**
* 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" ;
}
}
Copy @ RestController
@ RequestMapping ( "/mapping/users" )
public class MappingClassController {
@ GetMapping
public String user () {
return "get users" ;
}
@ PostMapping
public String addUser () {
return "post user" ;
}
@ GetMapping ( "/{userId}" )
public String findUser (@ PathVariable String userId) {
return "get userId = " + userId;
}
@ PatchMapping ( "/{userId}" )
public String updateUser (@ PathVariable String userId) {
return "update userId = " + userId;
}
@ DeleteMapping ( "/{userId}" )
public String deleteUser (@ PathVariable String userId) {
return "delete userId = " + userId;
}
}