截断字符串的休眠验证器LengthValidator [英] hibernate validator LengthValidator of truncated string

查看:94
本文介绍了截断字符串的休眠验证器LengthValidator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在休眠验证器中是否有与@Length相似的注释,但它限制在修剪后的字符串上.

Is there a similar annotation to @Length in hibernate validator but it restricted on a trimmed string.

例如:

我有

@Length(max= 2);
String str;

何时: str = " ab";
->它会通过.

when: str = " ab";
--> it will pass ok.

谢谢

推荐答案

据我所知,没有一个.

但是您可以轻松实现自己的

But you can easely implement your own.

另一种(不太好)的方法是添加一个修剪字符串的吸气剂.

The other (not so good) way is to add a getter which trim the string.

@Length(max= 2);
String getTrimmedStr() {
   return this.str.trim();
}

但是我认为实现自己的Validator是更清洁的方法.

But i think implementing your own Validator is the much cleaner approach.

这篇关于截断字符串的休眠验证器LengthValidator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆