restful 의 resource 클래스 의 각종 수신 매개 변수 방식
、@PathParam (@PathParam ,url )
가령http://localhost:8181/managerinfo/rs/helloworld/user/frank
resource 의 작성 방법 은:
@GET
@Path("/user/{condition}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_HTML)
public String getHelloWithPath(@PathParam("condition") String username) {
return "Hello Path UserName " + username;
}
、 @QueryParam (url 【 】 )
ajax 로 요청
$.ajax({
type: 'GET',
contentType: "application/json",
dataType: 'html',
url: 'http://localhost:8181/managerinfo/rs/helloworld/user',
data: {
username:"frank"
},
success:function(data){
alert(data);
}
실제 요청 주 소 는:http://localhost:8181/managerinfo/rs/helloworld/user?username=frank
다음 과 같은 몇 가지 표기 법 은 다음 과 같다.
http://blog.csdn.net/azhegps/article/details/72782704
여 기 는 자신 이 사용 하지 않 았 습 니 다. 기록 하 세 요.
3. @ DefaultValue
예: @GET @Path("/user") @Produces("text/plain") public User getUser(@QueryParam("name") String name, @DefaultValue("26") @QueryParam("age") int age) { ... } 브 라 우 저 요청http://host:port/user?name=rose시, name 값 은 rose 이 고, age 값 은 26 입 니 다. 4. @ FormParam @FormParam, 말 그대로 POST 가 요청 한 폼 매개 변수 에서 데 이 터 를 가 져 옵 니 다. 예 를 들 어: @POST @Consumes("application/x-www-form-urlencoded") publicvoid post(@FormParam("name") String name) { // Store the message } html 를 사용 하여 post 를 제출 한 사람 이 폼 에 대해 낯 설 지 않 을 것 이 라 고 믿 습 니 다. 이것 이 바로 html 에서 폼 을 모 의 하 는 요청 이 라 고 상상 할 수 있 습 니 다. 5. 사용 지도 대형 server 에서 매개 변수의 변화 로 인해 매개 변수 구조의 조정 은 상기 몇 가지 방식 으로 인해 문제 가 발생 할 수 있 습 니 다. 이 때 @ Context 주석 을 사용 하고 UriInfo 인 스 턴 스 를 얻 는 것 을 고려 할 수 있 습 니 다. 다음 과 같 습 니 다. @GET public String get(@Context UriInfo ui) { MultivaluedMap queryParams = ui.getQueryParameters(); MultivaluedMap pathParams = ui.getPathParameters(); } 맵 은 위의 몇 가지 상황 의 초 집합 이 라 고 생각 할 수 있 습 니 다. 왜냐하면 그것 은 위의 임의의 것 을 대체 할 수 있 기 때 문 입 니 다. 맵 은 context 입 니 다.
@Context ServletConfig、ServletContext、HttpServletRequest、HttpServletResponse HttpHeaders , :
@Path("/")
publicclass Resource {
@Context
HttpServletRequest req;
@Context
ServletConfig servletConfig;
@Context
ServletContext servletContext;
@GET
public String get(@Context HttpHeaders hh) {
MultivaluedMap headerParams = hh.getRequestHeaders();
Map pathParams = hh.getCookies();
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Javascript에서 XHR/fetch 메서드를 재정의하는 방법은 무엇입니까?XHR에 후크를 추가하거나 요청을 가져오기 위해 javascript의 Proxy 객체를 사용할 것입니다. 그리고 모든 요청에 데이터를 보내거나 모든 응답 데이터를 필터링하려는 시나리오에 직면합니다. API 호출에 후...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.