首页 > 解决方案 > @valid @requestBody kotlin 与实体到实体

问题描述

我在 kotlin 中遇到了有效请求的问题,因为我目前有一个由整数列表和另一个名为 emailData 的实体组成的对象,当我发送不完整或错误格式的电子邮件数据时,验证不会发生,让我进入控制器。我的代码和我在邮递员中的要求这些

 fun sendMessage(@Valid @RequestBody notificationData: NotificationData) {
    this.notificationManager.sendNotificationByType(notificationData)
}

data class NotificationData(
    @get:NotEmpty
    @get:NotNull
    @field:NotNull
    @Size(min = 2, max = 14)
    @get:JsonProperty("notification_type")
    var notificationType : List<Int> = listOf(),

    @Valid
    //@ @field:NotEmpty(message = "SRTERST enter id")
    @get:JsonProperty("email_data")
    var emailData : EmailData = EmailData()) 

data class EmailData(

    @NotNull
    @get:NotEmpty
    @get:JsonProperty("email_receiver")
    var emailReceiver : List<String> = listOf(),


    @NotNull
    @get:NotEmpty
    @get:JsonProperty("subject")
    var subject : String = "",

    @get:NotEmpty
    @NotNull
    @get:JsonProperty("template_id")
    var templateId : String = "",


    @get:NotEmpty
    @NotNull
    @get:JsonProperty("template_params")
    var templateParams : HashMap<String, String> = HashMap())

当我发送

{
"notification_type":["0"],
"email_data":{

    "subject":"test",
    "template_id":"d-1860fd6fa461449b88c578b124a0b331"

}

}

emailData 的验证不起作用。

标签: spring-bootkotlin

解决方案


推荐阅读