简体   繁体   English

@Size注释未修剪空格

[英]@Size annotation not trimming whitespace

I have an Entity bean and one of its String-type properties has a @Size annotation as follows: 我有一个Entity bean,它的String-type属性之一具有@Size注释,如下所示:

@PSanityCheck
@Size(min = 8, max = 8, message = "validation.servicecode_length")
@NotEmptyData
@Column(name = "servicecode")
@Field
private String servicecode= "";

However, if I type a string containing a whitespace in the beginning, for example " 1234567" it will accept it as input made of 8 characters. 但是,如果我在开头输入一个包含空格的字符串,例如“ 1234567”,它将接受它作为由8个字符组成的输入。 How to make it trim off the whitespace? 如何使其修剪空白? Is there an annotation for that? 有注释吗? The UI is made with Vaadin-framework. UI由Vaadin框架构成。

您可以为此使用@Pattern批注和正则表达式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM