1:Spring applicationContext.xml配置文件如下(只描述了定时器配置):
2:action层简单的调用Service层的方法:
synchroDataService.synchrodata();
3:service层:
InputStream inputStream = null;
OutputStream fos = null;
try{
SimpleDateFormat sdformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// inputStream = new FileInputStream(this.getClass().getClassLoader().getResource("webData.properties").getPath());
inputStream = this.getClass().getClassLoader().getResourceAsStream("webData.properties");
Properties properties = new Properties();
properties.load(inputStream);
String updateID = new String(properties.getProperty("updateID").getBytes("ISO8859_1"), "UTF-8");
String registerID = new String(properties.getProperty("registerID").getBytes("ISO8859_1"), "UTF-8");
if(inputStream != null){
inputStream.close();
}
String code_update[] = { "SYS302001", "SYS302003" };
String code_register[] = { "SYS302005", "SYS302006" };
fos = new FileOutputStream(this.getClass().getClassLoader().getResource("webData.properties").getPath());
if (StringUtils.isNotEmpty(updateID)) {
List listU = getListData(code_update, updateID,sdformat);
dataInsert(listU,sdformat);
properties.setProperty("updateID", MaxID);
}
if (StringUtils.isNotEmpty(registerID)) {
List listR = getListData(code_register, registerID,sdformat);
dataInsert(listR,sdformat);
properties.setProperty("registerID", MaxID);
}
properties.store(fos, null);
}finally{
if(fos != null){
fos.flush();
fos.close();
}
}