JAX-REST 的新手(jersey 1.8 impl)
我有一个资源类“/你好”
package com.lbs.rest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/hello")
public class Test {
//-- produces MIME type text/plain
@GET
@Produces(MediaType.TEXT_PLAIN)
public String thankYouTxt(){
System.out.println("thankYouTxt");
return "thankYouTxt\n";
}
//-- consumes MIME type text/plain
@GET
@Consumes(MediaType.TEXT_PLAIN)
public String thankYouInputTxt(){
System.out.println("thankYouInputTxt");
return "thankYouInputTxt";
}
//-- produces MIME type text/html
@GET
@Produces(MediaType.TEXT_HTML)
public String thankYouHTML(){
System.out.println("thankYouHTML");
return "thankYouTxtHTML";
}
//-- consumes MIME type text/html
@GET
@Consumes(MediaType.TEXT_HTML)
public void thankYouInputHTML(){
System.out.println("thankYouInputHTML");
//return "thankYouInputHTML";
}
//-- produces MIME type text/xml
@GET
@Produces(MediaType.TEXT_XML)
public String thankYouXML(){
System.out.println("thankYouXml");
return "<?xml version=\"1.0\"?> <message>thankYouTxt</message>";
}
//-- consumes MIME type text/xml
@GET
@Consumes(MediaType.TEXT_XML)
public String thankYouInputXML(){
System.out.println("thankYouInputXML");
return "thankYouInputXML";
}
}
当我发送带有 header 的请求时Content-Type : text/html
,我希望 the@Produces
和@Consumes
annotated 方法thankYouHTML()
都thankYouInputHTML()
被调用。
但只有@Produces thankYouHTML()
方法被调用?为什么?为什么不也调用带@Consumes
注释的方法?thankYouHInputTML()