Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/349.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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 如何在@RequestMapping中使用{within value(或path)_Java_Spring Mvc_Request Mapping - Fatal编程技术网

Java 如何在@RequestMapping中使用{within value(或path)

Java 如何在@RequestMapping中使用{within value(或path),java,spring-mvc,request-mapping,Java,Spring Mvc,Request Mapping,示例URL如下所示: api/v1/query?query=up{device=“device_1”} 其中,设备_1是@PathVariable 我用以下方法进行测试: @RequestMapping(value="/api/v1/query?query=up{device=\"${device}\"}", method = RequestMethod.GET) String getLastPosting(@PathVariable("device") Str

示例URL如下所示:

api/v1/query?query=up{device=“device_1”}

其中,设备_1是@PathVariable

我用以下方法进行测试:

@RequestMapping(value="/api/v1/query?query=up{device=\"${device}\"}",
                method = RequestMethod.GET) String 
getLastPosting(@PathVariable("device") String device);
答复:

出现意外错误(类型=内部服务器错误, 状态=500)。内容:不允许使用方法


关于正确的格式有什么想法吗?

这个URL看起来真的很奇怪,而且这些大括号可能是URL中的错误源,它们需要被
%7B
%7D
替换

我认为你最好使用一个更简单的方法,例如:

api/v1/query?query=up&device=Device_1
然后按以下方式声明控制器:

@RequestMapping(value="/api/v1/query", method = RequestMethod.GET) 
public String getLastPosting(@RequestParam(value="query") String query, 
                             @RequestParam(value="device") String device) {
}
其他选项将使用Unicode作为花括号(但我不建议使用这些选项)


@RequestMapping(value=“/api/v1/query/{device}”,method=RequestMethod.GET)您的参数是什么?您绝对需要这种格式吗?您不能使用
api/v1/query吗?例如query=up&device=device\u 1
?甚至
api/v1/query/up/device/device\u 1
/api/v1/query=up%7Bdevice="Device_1"%7D

@RequestMapping(value="/api/v1/{query}",method = RequestMethod.GET)
public String getLastPosting2(@PathVariable("query") String query){

  // query is query=up{device="Device_1"}
  // you would need to parse it to extract the device name

}
/api/v1/query=up%7Bdevice="Device_1"%7D

@RequestMapping(value="/api/v1/query",method = RequestMethod.GET)
public String getLastPosting3(@RequestParam("query") String query){

  // query is up{device="Device_1"}
  // you would need to parse it to extract the device name

}