FUNCTION --1
@Path("/object/")
public Class TestService {
@GET
@Produces({ "application/json" })
@Path("/{uid}")
public Response hello(@PathParam("uid") String uid){
System.out.println("UID-->" + uid);
return Response.status(Response.Status.OK).build();
}
=====================================================================
FUNCTION --2
@Path("/object/")
public Class TestService {
@GET
@Produces({ "application/json" })
@Path("/{uid}/")
public Response hello(@PathParam("uid") String uid){
System.out.println("UID-->" + uid);
return Response.status(Response.Status.OK).build();
}
当我点击:http://base-url/object/abc
时函数--1给出:UID - > null
功能--2给出:UID - > abc
在函数--2中,我只是在@path中的uid之后附加了斜杠。但是根据文档,添加前导斜杠并不是强制性的。我不明白为什么函数--1然后返回null?
答案 0 :(得分:1)
URI中的尾随public abstract class DelegatingConverterBase : JsonConverter
{
private readonly JsonConverter original;
protected DelegatingConverterBase(JsonConverter original)
{
this.original = original;
}
public override void WriteJson(
JsonWriter writer, object value, JsonSerializer serializer) =>
original.WriteJson(writer, value, serializer);
public override object ReadJson(
JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) =>
original.ReadJson(reader, objectType, existingValue, serializer);
public override bool CanRead => original.CanRead;
public override bool CanWrite => original.CanWrite;
public override bool CanConvert(Type objectType) => original.CanConvert(objectType);
}
是可选的,可以省略。正如你在@Path documentation中所说的那样:
为了对基URI进行绝对路径绝对化,路径中的前导'/'被忽略,基URI被视为以'/'结尾
在这种情况下,它似乎是您正在使用的实现的缺陷