public class JavaUtil {
public static String replaceFieldVal(Object t,String temlateStr){
if (null == t || null == temlateStr || temlateStr == ""){
return "";
}
String fieldName,fieldVal;
Field[] fields = t.getClass().getDeclaredFields();
for (Field field : fields){
field.setAccessible( true );
try {
fieldName = field.getName();
fieldVal = null == field.get(t) ? "" : field.get(t) + "";
if (temlateStr.contains(fieldName)){
String nameStr = "${" + fieldName + "}";
temlateStr = temlateStr.replace(nameStr, fieldVal);
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
return temlateStr;
}
}