java 字符 字节数

97 阅读1分钟
public boolean isValid(String value, ConstraintValidatorContext context) {   
 String s ="dfdfd"   s   
 if (value == null) {       
    return true;    
    }    
    try {        
    byte[] bytes = value.getBytes(characterSet);        
    return bytes.length <= maxValue && bytes.length >= minValue;    
    } catch (UnsupportedEncodingException e) {     
       return false;    
    }
}