package com.java4s;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
@Path("/customers")
public class RestServicePathParamJava4s {
@GET
@Path("{name}/{country}")
@Produces("text/html")
public Response getResultByPassingValue(
@PathParam("name") String name,
@PathParam("country") String country) {
String output = "Customer name - "+name+", Country - "+country+"";
return Response.status(200).entity(output).build();
}
}
ใน web.xml ฉันได้ระบุรูปแบบ URL เป็น /rest/*
และใน RestServicePathParamJava4s.java
เราระบุระดับคลาส @Path
เป็น /customers
และระดับเมธอด @Path
เป็น {name}/{country}
ดังนั้น URL สุดท้ายควรเป็น
http://localhost:2013/RestPathParamAnnotationExample/rest/customers/Java4/USA
และควรแสดงการตอบสนองเป็น
Customer name - Java4, Country - USA
ถ้าฉันให้อินพุต 2 ที่ระบุด้านล่างแสดงว่ามีข้อผิดพลาด วิธีแก้ปัญหานี้?
http://localhost:2013/RestPathParamAnnotationExample/rest/customers/Java4:kum77./@.com/USA`
ที่นี่ Java4:kum77./@.com
อันนี้เป็นหนึ่งสตริงและมีเครื่องหมายทับ วิธียอมรับสิ่งนี้โดยใช้ @PathParam
หรืออะไรก็ตามที่ฉันต้องใช้ MultivaluedMap
หากใครรู้สิ่งนี้โปรดช่วยฉันด้วย ถ้าใครรู้ว่า MultivaluedMap
คืออะไร ขอยกตัวอย่างง่ายๆ ให้ฉันหน่อย