例如以下方法: 这个是切换当前用户语言的一个接口
@RestController
@Validated
public class LocaleController extends BaseController {
@PostMapping(path = "/change_locale")
public Ret<String> change(
@NotBlank(message = "语言不能为空")
@RequestParam(name = "locale")
String localeStr,
HttpServletRequest request
) {...}
如果这么调用 http://lcoalhost:8080/change_locale
, 返回spring定义的原生错误信息 "Required String parameter 'locale' is not present"
如果这么调用 http://lcoalhost:8080/change_locale?locale=
, 这样才会报我自己的错误 "语言不能为空"
我看了 @Blank 这个注解, 是包含 Null 这种验证的, 如下
* Validate that the annotated string is not {@code null} or empty.
* The difference to {@code NotEmpty} is that trailing whitespaces are getting ignored.
请问如何统一呢
@RequestParam
的required设置为false