需求:清空三个月前的操作日志,并生成备份.sql文件 Java实现

[复制链接]
发表于 2022-8-9 14:38:06 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
备份
  1. /**
  2.      * 主方法
  3.      * @param tableName 表名
  4.      * @param column   条件字段
  5.      */
  6.     public void insertSql(String tableName, String column){
  7.         // 查询数据
  8.         List<Map<?, ?>> list = deptMapper.getDataByTable(tableName, column);
  9.         logger.info("@@@@  开始备份" + tableName + "数据@@@@");
  10.         // 拼接insert List
  11.         List<StringBuilder> insertSqlList = new ArrayList<>();
  12.         for (Map<?, ?> map : list) {
  13.             StringBuilder sb = new StringBuilder();
  14.             sb.append(getInsertSql(tableName, map));
  15.             insertSqlList.add(sb);
  16.         }
  17.          // 保存成文件格式
  18.         if (insertSqlList.size() > 0){
  19.             createFile(insertSqlList, tableName);
  20.         }
  21.     }
复制代码
  
[code][/code] 
查询三个月前的操作数据:
[code]  @Select("select * from ${table} where ${column} < curdate()-INTERVAL 3 month")    List
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表