package com.service;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;
import com.dao.UserInfo;
public class InsertDataToSDP {
public static void main(String[] args) throws FileNotFoundException, IOException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ReflectiveOperationException, RuntimeException {
Properties pps = new Properties();
InputStream in = new BufferedInputStream(new FileInputStream("src/resources/properties/SDP_ExcelMapDb.properties"));
//prop.load(in);//直接这么写,如果properties文件中有汉子,则汉字会乱码。因为未设置编码格式。
pps.load(new InputStreamReader(in, "utf-8"));
String key = "用户名";
String columnName = pps.getProperty(key);
String setMethodName = "set" + columnName.substring(0, 1).toUpperCase() + columnName.substring(1);
//获取方法
UserInfo userInfo = new UserInfo();
Method setMethod = userInfo.getClass().getDeclaredMethod(setMethodName, String.class);
//调用方法
setMethod.invoke(userInfo, "bbb");
//查看运行效果
System.out.println(userInfo.getUserName());
}
}