背景
@ApiModelProperty(value = "markdown原始内容", required = true)
@NotBlank(message = "markdown内容不能为空")
var md: String? = "",
验证不生效,需要修改一下
@ApiModelProperty(value = "markdown原始内容", required = true)
@field:NotBlank(message = "markdown内容不能为空")
var md: String? = "",
统一返回错误,可以针对不的异常类型进行捕获,比如
@ExceptionHandler(BindException::class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
fun handle(e: BindException): R<Any> {
val err = e.bindingResult.fieldErrors
val msg = err[0].defaultMessage
return R.fail(9005, msg ?: "未知错误")
}
Top comments (0)