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
Spring mvc @RequestParam如何处理框架不正确的URL_Spring Mvc - Fatal编程技术网

Spring mvc @RequestParam如何处理框架不正确的URL

Spring mvc @RequestParam如何处理框架不正确的URL,spring-mvc,Spring Mvc,我正在进行如下的方法测试,并进行RESTfulWebService调用以获取数据 @RequestMapping(value ="/select", method = RequestMethod.GET) @ResponseBody public String test( @RequestParam(value="begin", defaultValue="0",required=false) final String begin ) { //Some java code } **RESTfu

我正在进行如下的方法测试,并进行RESTfulWebService调用以获取数据

@RequestMapping(value ="/select", method = RequestMethod.GET)
@ResponseBody
public String test(
@RequestParam(value="begin", defaultValue="0",required=false) final String begin
)
{
//Some java code
}

**RESTful Webservice Call:**
http://localhost:8081/a/b/c/select?begin=1
Returning the data properly

http://localhost:8081/a/b/c/select?begin:1
Here in the url = has been replaced with : for negative testing.
Here Spring ignores the given value 1 and picks the default value 0 and returns the data accordingly without errors

Question:
But I want to capture the actual URL field with value which is begin:1, do some validation and display error message that the url is incorrect.

I understood that begin:1 is not considered as part of url by spring and hence picks the default value. Wondering is there a way in Spring to capture the wrongly framed url's.
Any pointers would be helpful. Many Thanks!

那么,您是否有一个不提供客户端库的restful服务?您需要考虑的一些事情是API开发,其中之一是HATOOS或超媒体。您的客户端是否应该创建自己的URL?顺便说一句,您可以为请求参数设置一个“默认值”。您可以查看它是否使用默认值,如果是默认值,则返回错误消息。感谢您的回复。客户将使用我们提供的URL?将是基本url,还有许多其他参数类似于begin=1“开始”被指定为默认值0和“必需=false”。我无法检查默认值并返回错误消息,因为在某些情况下场景是有效的。用户甚至可以拍摄url,这里的begin默认为0。是的,您需要深入了解HATEOS并逐步构建url。如果这种情况是有效的,但仅在某些上下文中,您需要将它们指向这些上下文。