Request error: Required String parameter 'id' is not present

When the development front-end requests the back-end address http://127.0.0.1:8082/getDataMode2 through ajax , an error is reported when the parameter id or mode is empty.

The backend code is:

@GetMapping("/getDataMode2")
public RespBean getDataMode2(@RequestParam(name = "id") String id,@RequestParam(name = "mode") String mode){
       return new RespBean();
}

 reason:

Note that the required parameter of @RequestParam is true by default, that is, it cannot be empty, just add require=false

Modified code:

@GetMapping("/getDataMode2")
public RespBean getDataMode2(@RequestParam(name = "id",required = false) String id,@RequestParam (name = "mode",required = false) String mode){
        return new RespBean();
}

 

Guess you like

Origin blog.csdn.net/weixin_46205984/article/details/127447000