/**
* 序列化
* @param list
* @param filename
* @throws IOException
*/publicstaticvoidserializeList(List<Map<String,Object>> list,String filename)throwsIOException{try(ObjectOutputStream oos =newObjectOutputStream(newFileOutputStream(filename))){
oos.writeObject(list);}}/**
* 反序列化
* @param filename
* @return
* @throws IOException
* @throws ClassNotFoundException
*/publicstaticList<Map<String,Object>>deserializeList(String filename)throwsIOException,ClassNotFoundException{try(ObjectInputStream ois =newObjectInputStream(newFileInputStream(filename))){@SuppressWarnings("unchecked")List<Map<String,Object>> list =(List<Map<String,Object>>) ois.readObject();return list;}}/**
* 查询数据
*
* @return
*/publicList<Map<String,Object>>getdata(){JdbcTemplate jdbcTemplate2 =getJdbcTemplate2("jdbc:mysql://localhost:3306/gzw?serverTimezone=UTC","root","root");String sql ="select name,max(mon) from (\n"+"select name,lx,sum(money) mon from user GROUP BY name,lx order by name ) t1 GROUP BY name order by name ";List<Map<String,Object>> maps = jdbcTemplate2.queryForList(sql);return maps;}publicListgetLx()throwsIOException,ClassNotFoundException{String name ="gzw.data"+sdf.format(newDate());//先判断有没有文件String dir ="E:\\test\\";File file =newFile(dir + name);//有文件就用文件数据 -数据多久更新if(file.exists()){List<Map<String,Object>> objects =deserializeList(dir + name);return objects;}else{//没有文件数据,查询sqlList<Map<String,Object>> getdata =getdata();//序列化,保存为文件serializeList(getdata, dir + name);return getdata;}}