简体   繁体   中英

Bean Validation transforms Object RequestParam into @RequestBody

I have the following:

 @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
 public ResponseEntity<LoginResponse> getLoginStatus(@Valid LoginRequest loginRequest){
        //some stuff here
 }

The loginRequest paramater is a @RequestParam , but, because it is a custom object, the @RequestParam annotation in front of the object is not needed. The problem is that when any bean-validation annotation is put in front of the custom object, the object is transformed into a body parameter( @RequestBody ), but we want to validate the object as request param, not body param.

Could anyone help me, please?

The reason why the LoginRequest attributes became part of the RequestBody , and not of RequestParameters anymore, is due to springfox-swagger version 2.6.1. Upgrading to version 2.7.0 fixed this issue for us.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM