截取指定错误信息长度
截取指定长度错误信息
 
/** * 截取消息长度 * * @param errorMsg 消息 * @param interceptLength 截取长度 * @return String */ private String getMessage(String errorMsg, int interceptLength) { if (StringUtils.isBlank(errorMsg)) { return ""; } int minLength = Math.min(interceptLength, errorMsg.getBytes(StandardCharsets.UTF_8).length); int byteLength = 0; String subStr = ""; do { subStr = errorMsg.substring(0, minLength--); byteLength = subStr.getBytes(StandardCharsets.UTF_8).length; } while (byteLength > interceptLength); return subStr; }
posted on 2022-07-25 09:48 lovezj9012 阅读(23) 评论(0) 收藏 举报
 
                    
                     
                    
                 
                    
                 
 
                
            
         
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号