這裏,請求帕拉姆字符串是:如何使用BeanUtils轉換器來列表?
的firstName =插孔&的lastName =百合&性別= 1種&食物=牛排&食物=比薩&報價=輸入你+ +收藏+報價! &教育= Jr.High & TOFD =日
,並映射類是:
public class Student {
private String firstName;
private String lastName;
private Integer gender;
private List<String> foods;
private String quote;
private String education;
private String tOfD;
getXxx()....;
setXxx()....;
}
而現在,我想編寫一個通用的Util類的字符串轉換爲一個bean。
public final class InjectUtil<T> {
private static final Logger LOGGER = LoggerFactory.getLogger(InjectUtil.class);
public static <T> T converter2Obj(String source, Class<T> tClass) {
T t = null;
try {
t = tClass.newInstance();
if(source != null && source.length() > 0) {
String[] fields = source.split("&");
for(String field : fields) {
String[] fieldKeyValue = field.split("\\=");
String fieldKey = fieldKeyValue[0];
String fieldValue = fieldKeyValue[1];
// help
}
}
} catch(InstantiationException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
return t;
}
}
照顧的幫助下,我該如何使用BeanUtils的轉換器中的「食品=牛排&食物=比薩」的列表屬性。