//获取数据库字段个数
Class<LoginUser> loginUserClass = LoginUser.class;
int length = loginUserClass.getDeclaredFields().length;
//主要用于字段信息填写完成度
Set keySet = loginUserHisPage.getRecords().get(0).keySet();
ArrayList keyArray = new ArrayList();
keyArray.addAll(keySet);
int countK = 0;
for (int i = 0; i < keyArray.size(); i++) {
Object o = keyArray.get(i);
Object o1 = loginUserHisPage.getRecords().get(0).get(o);
if (o1 != null) {
if (o.equals("uuid") || o.equals("mwPassword")) {
} else {
countK++;
}
}
}
double completeSum = 0 * 1.0;
if (countK == 0) {
completeSum = 0;
} else {
completeSum = (countK * 1.0 / (27 * 1.0) );
}
if (completeSum >= 1) {
completeSum = 1;
}
DecimalFormat decimalFormat = new DecimalFormat(".00%");
String formatSum = decimalFormat.format(completeSum);
获得一个0%~100%之间的String返回给前端。
注意:countK可能为零,需要做一下判断,我的countK不可能为零,这里就没做判断!