spring-boot - @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 的验证不起作用。
解决方案
推荐阅读
- annotations - 使用 Postman 的 D365 机会备注附件
- python - 具有多个索引的 Pandas 数据透视表排序
- javascript - 如何使用动态生成的属性名称访问表单属性以填充多个下拉列表
- c# - 如何在 xamarin.forms 中为 collectionview 中的元素设置动画
- css - 前两个单元格的动态 CSS 网格
- python - 在 Tree View Odoo 14 中禁用可编辑字段
- html - 如何在角度原生脚本上反转换行布局的顺序
- sql - 未能在 redshift 中对特定模式的表授予选择权限
- xamarin.forms - 为什么 Syncfusion Xamarin.Forms DataForm 忽略列跨度的网格附加属性?
- android - 根据情况更改值,并保存到 SharedPreferences。如果情况发生变化,请分配新值而不是加载前一个值