首页 > 其他 > 详细

将类中的类型为 String 的属性值中的空格去掉

时间:2019-05-06 16:49:28      阅读:156      评论:0      收藏:0      [点我收藏+]
/**
* @Description: 将 类中的 类型为 String 的属性值中的空格去掉
* @Param: 要转换的类
* @return: 转换完的类
* @Author: lingtong
* @date: 2019/03/27 16:00
*/
public static void trimBean(Object model) throws Exception {
//int a = 1/0;
Class clazz = model.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
if (field.getGenericType().toString().equals("class java.lang.String")) {
Method getMethod = clazz.getMethod("get" + getMethodName(field.getName()));
String value = (String) getMethod.invoke(model);// 调用getter方法获取属性值
if (!isEmpty(value)) {
//value = value.replaceAll(" ", "");
value = value.trim();
field.setAccessible(true);
field.set(model, value);
}
}
}
}

将类中的类型为 String 的属性值中的空格去掉

原文:https://www.cnblogs.com/lt3232696/p/10820373.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!