Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将搜索条件声明为参数REST API方法_Java_Restful Url_Restapi - Fatal编程技术网

Java 如何将搜索条件声明为参数REST API方法

Java 如何将搜索条件声明为参数REST API方法,java,restful-url,restapi,Java,Restful Url,Restapi,URI看起来像/api/v2/Employee?filter[search_key]=1234 我想为上面的URI定义RESTAPI方法,但我不知道如何使用[search_key] @Path("/Employee") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public interface EmployeeServices {

URI看起来像/api/v2/Employee?filter[search_key]=1234 我想为上面的URI定义RESTAPI方法,但我不知道如何使用[search_key]

    @Path("/Employee")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public interface EmployeeServices {
    
    
    @GET
    public List<Employee> searchEmployee(@QueryParam("filter") String filter);
@Path(“/Employee”)
@产生(MediaType.APPLICATION_JSON)
@使用(MediaType.APPLICATION_JSON)
公共接口EmployeeServices{
@得到
公共列表searchEmployee(@QueryParam(“过滤器”)字符串过滤器);

}请澄清您的问题

以下是使用应用程序URL中提供的路径参数的方法:

@GET
@Path("/Employee/{filter}")
@Produces({MediaType.APPLICATION_JSON})
public List<Employee> searchEmployee(@PathParam("filter") String filter){
   //your code
}
@GET
@路径(“/Employee/{filter}”)
@产生({MediaType.APPLICATION_JSON})
公共列表searchEmployee(@PathParam(“筛选器”)字符串筛选器){
//你的代码
}
如果您试图在这里进行一些实际的后端处理(创建一个控制器类),那么这应该是一个类而不是一个接口

如果您真的打算使用@QueryParam,请查看以下帖子:

您的问题无法理解,请描述您的问题,并阅读如何在StackOverflow上正确发布问题。thnaks我的问题是如何为上述url括号编写方法签名部分[]此答案中的“筛选器”可以替换为任何内容。您只需要在签名中获得与URL中相同的QueryParam/PathParam。“[”是一个通用分隔符,如果不对其进行编码,则无法在URL中使用。RFC 3986定义了以下一组可用作分隔符的保留字符。因此,它们需要URL编码::/?#/[]/@!$&'()*+,;=检查此处字符的URL编码: