민서네집

[SpringMVC] RequestMapping 의 전략 본문

Spring

[SpringMVC] RequestMapping 의 전략

브라이언7 2012. 8. 23. 05:41

[출처] http://olc.oss.kr


빠르게 살펴보는 Spring MVC 모든 것!! 

강사: 표준프레임워크 오픈커뮤니티 23차 기술세미나 박용권 님

등록일: 2012.08.02


@RequestMapping - By HTTP method


@Controller

public class MemberController {


@RequestMapping(method=RequestMethod.GET)

public String list() { + }


@RequestMapping(method=RequestMethod.POST)

public String add() { + }


@RequestMapping(method=RequestMethod.PUT)

public String edit() { + }


@RequestMapping(method=RequestMethod.DELETE)

public String delete() { + }

}


@RequestMapping의 전략들

  • By presence of query parameter
- @RequestMapping(value="path", params="name")
- http://open.egovframe.go.kr/path?name=springmvc
  • By presence of request header
- @RequestMapping(value="path", header="Accept=application/json")
- $.getJSON('http://open.egovframe.go.kr/path', function(data){...})
  • By Consumers/Produces
- @RequestMapping(value="path", consumes="application/json")
- @RequestMapping(value="path", produces="application/json")


MethodParameter로 Request 데이터 받기


  • A query parameter value
- @RequestParam("name")
  • A group of query parameter values
- A custom JavaBean with a getName()/setName() pair for each parameter
  • A path element value
- @PathVariable("var")
  • A request header value
- @RequestHeader("name")
  • A cookie value
- @CookieValue("name")
  • The request body
- @RequestBody
  • The request body and any request header
- HttpEntity<T>


Comments