原理按sort ()方法排序。
//*
私有字符串获取代码字符串(
axdxf对象=this;
Map map=new HashMap (;
//获取所有属性组
field [ ] super field=this.getclass (.get super class ) ).getDeclaredFields );
Field[] selfField=this.getClass ().getDeclaredFields );
列表所有字段=new ArrayList (;
all field.addall (arrays.stream (super field ).collectors.tolist ) );
all field.addall (arrays.stream (self field ).collect ) collectors.tolist );
for(intI=0; i allfield.size (; I ) {
字段字段=all field.get (I;
if (axdx fs.nonnull (field.get annotation ) JSONfield.class ) ) {
field name=field.get annotation (JSON field.class ).name );
}
field.set accessible (真;
try {
if(field.get(object )==null ) {
valString=' ';
} else {
valstring=field.get(object ).toString );
}
map.put (字段名称,valString );
} catch (illegalargumentexceptione ) {
//todo auto-generated catch块
e .打印堆栈跟踪(;
(匹配(illegalaccessexceptione ) ) ) )。
//todo auto-generated catch块
e .打印堆栈跟踪(;
}
}
Collection keyset=map.keySet (;
列表列表=new ArrayList (keyset );
collections.sort (列表;
for(intI=0; i list.size (; I ) {
if(I==(list.size ) (- 1 ) ) )。
if (! string utils.isempty (map.get (list.get (I ) ) ) ) )。
rawstring=list.get(I ) '=' map.get (list.get ) I );
}
} else {
if (! string utils.isempty (map.get (list.get (I ) ) ) ) )。
rawstring=list.get(I )=' map.get (list.get ) ) );
}
}
}
返回原始字符串;
}