Your question is "The current situation is that if the incoming parameter is not a number, it will be returned 400 Bad Request and you don't know why?"
Still, "You want to automatically return 400 Bad Request when the incoming parameter is not a number"
Added:
Can you change it like this? If you are using spring4:
@RequestMapping("/test")
@ResponseBody
public String test(@RequestParam("id") Long id, BindingResult result){
if (result.hasErrors()) {
return "返回你想返回的";
}
return id + "";
}
I haven’t written for a long time, it should be ok
Added:
It seems to be specified@Valid之类的注解的,你得仔细查查spring的文档,我实在不确定annotation是不是我写的这个@RequestParam(depending on whether your parameters come from the url or other places)
If you are so confused, just accept itObject id 然后第一行代码判断id instanceof Long Just kidding. . If what is passed in is not a number, it probably won’t go to your method.
Your question is "The current situation is that if the incoming parameter is not a number, it will be returned
400 Bad Request
and you don't know why?"Still, "You want to automatically return
400 Bad Request
when the incoming parameter is not a number"Added:
Can you change it like this? If you are using
spring4
:Added:
It seems to be specified
@Valid
之类的注解的,你得仔细查查spring
的文档,我实在不确定annotation
是不是我写的这个@RequestParam
(depending on whether your parameters come from the url or other places)If you are so confused, just accept it
Object id
然后第一行代码判断id instanceof Long
Just kidding. .If what is passed in is not a number, it probably won’t go to your method.