我正在使用GAE生成servlet,一切正常,但是,端点的路由总是添加我要删除的" v1",这是路由的示例是:
https://xxxx.appspot.com/services/test/v1/imprimirpersona?n=5
我希望它如下:
https://xxxx.appspot.com/services/test/imprimirpersona?n=5
,但我不知道如何实现。
web.xml:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!-- Wrap the backend with Endpoints Frameworks v2. -->
<servlet>
<servlet-name>EndpointsServlet</servlet-name>
<servlet-class>com.google.api.server.spi.EndpointsServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value>com.example.skeleton.MyApi,
com.example.skeleton.Foo</param-value>
</init-param>
</servlet>
<!-- Route API method requests to the backend. -->
<servlet-mapping>
<servlet-name>EndpointsServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
myapy.class:
@Api(name = "test")
public class MyApi {
@ApiMethod(name = "datosPorUrl", httpMethod = "GET")
public Message datosPorUrl(Message message, @Named("n") @Nullable Integer n) {
message.setMessage("El valor recibido es : " + n);
return message;
}
@ApiMethod(name = "imprimirPersona", httpMethod = "POST")
public Message imprimirPersona(Persona persona, @Named("n") @Nullable Integer n) {
Message message = new Message();
message.setMessage("Test : El valor nombre es : " + persona.getNombre()
+ " la edad es : " + persona.getEdad());
return message;
}
}
向所有@ApiMethod
声明添加路径参数:@ApiMethod(..., path = "/test/imprimirPersona")
。领先的斜线是这里的关键。