【问题标题】:Hibernate Validator with Hibernate Dynamic Models (No Entity Class)Hibernate Validator with Hibernate Dynamic Models (No Entity Class)
【发布时间】:2021-09-29 12:56:32
【问题描述】:

我正在使用休眠动态模型来创建 CRUD。我想知道如何验证 http 请求 (@Valid) 注释,因为我没有任何实体或 DTO。

@PostMapping("/signup")
public ResponseEntity<RestResponse> signup(@Valid @RequestBody Map<String, Object> user) {
    var restResponse = new RestResponse<>();

    restResponse.setStatusCode(HttpStatus.OK.value());
    restResponse.setResponse(user);

    return ResponseEntity.status(HttpStatus.OK)
            .body(restResponse);
}

【问题讨论】:

    标签: spring-boot hibernate hibernate-validator


    【解决方案1】:

    你不能,因为没有用于 bean 验证注释的 java 类,这是 bean 验证的唯一基础。也许您应该切换到一个适当的基于类的模型,这也将使您的应用程序更容易理解和调试

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-11
      • 1970-01-01
      相关资源
      最近更新 更多