简体   繁体   English

Bean验证将对象RequestParam转换为@RequestBody

[英]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. loginRequest参数是@RequestParam ,但是由于它是一个自定义对象,因此不需要该对象前面的@RequestParam批注。 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. 问题在于,当将任何bean验证注释放在自定义对象前面时,该对象将转换为主体参数( @RequestBody ),但是我们要将对象验证为请求参数,而不是主体参数。

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. LoginRequest属性成为RequestBody而不是RequestParameters一部分的原因是由于springfox-swagger版本2.6.1所致。 Upgrading to version 2.7.0 fixed this issue for us. 升级到版本2.7.0为我们解决了此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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