当前位置: 首页 > news >正文

上海移动云网站建设深圳百度推广属于哪家公司

上海移动云网站建设,深圳百度推广属于哪家公司,甘肃省疫情防控最新通知,网站推广网络需求 业务背景是需要某单机程序需要把正在进行的任务导出,然后另一台电脑上单机继续运行,我这里选择的方案是同步SQL形式,并保证ID随机,多个数据库不会重复。 实现 package com.nari.web.controller.demo.controller;import cn…

需求

业务背景是需要某单机程序需要把正在进行的任务导出,然后另一台电脑上单机继续运行,我这里选择的方案是同步SQL形式,并保证ID随机,多个数据库不会重复。

实现

package com.nari.web.controller.demo.controller;import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.List;
import java.util.Map;@RestController
@RequestMapping("/download")
public class DemoController {@Resourceprivate JdbcTemplate jdbcTemplate;/*** 二进制转成十六进制* 这里主要是处理图片数据,因为数据库存了图片Base64*/private String bytesToHexString(byte[] bytes) {StringBuilder hexString = new StringBuilder();for (byte b : bytes) {String hex = Integer.toHexString(0xff & b);if (hex.length() == 1) {hexString.append('0');}hexString.append(hex);}return hexString.toString();}/*** 导出指定表SQL**/@GetMapping("/table/{tableName}")public void downloadTable(@PathVariable String tableName, HttpServletResponse response) throws IOException {// 查询表数据List<Map<String, Object>> tableData = jdbcTemplate.queryForList("SELECT * FROM " + tableName);// 查询表结构List<Map<String, Object>> tableStructure = jdbcTemplate.queryForList("SHOW CREATE TABLE " + tableName);// 拼接SQL插入语句StringBuilder sqlBuilder = new StringBuilder();sqlBuilder.append(tableStructure.get(0).get("Create Table")).append(";\n\n");for (Map<String, Object> row : tableData) {StringBuilder valuesBuilder = new StringBuilder();StringBuilder columnsBuilder = new StringBuilder();for (Map.Entry<String, Object> entry : row.entrySet()) {columnsBuilder.append(entry.getKey()).append(", ");if (entry.getValue() instanceof byte[]) {byte[] binaryData = (byte[]) entry.getValue();String hexString = bytesToHexString(binaryData);valuesBuilder.append("0x").append(hexString).append(", ");} else {valuesBuilder.append("'").append(entry.getValue()).append("', ");}}String columns = columnsBuilder.substring(0, columnsBuilder.length() - 2);String values = valuesBuilder.substring(0, valuesBuilder.length() - 2);sqlBuilder.append("INSERT INTO ").append(tableName).append(" (").append(columns).append(") VALUES (").append(values).append(");\n");}// 构建响应response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + tableName+".sql");response.getWriter().write(sqlBuilder.toString());}}

结果

能看到这边图片已经正常导出了

image-20230808213359441

http://www.hkea.cn/news/242104/

相关文章:

  • 用dede做的网站首页电子商务网络营销
  • 最好的做任务赚钱网站网络域名怎么查
  • 建设部规范网站百度app关键词优化
  • 骏域网站百度怎么收录网站
  • 网站robots.txt查看九江seo公司
  • 建设阿里妈妈网站搜索引擎排名优化seo
  • 自学网站建设作业创建网站免费
  • 营销网站定制的优势成品网站源码的优化技巧
  • 高职学院网站建设方案广告制作
  • table表格 做的网站营销案例分析报告模板
  • pc端网站做移动适配教育培训机构管理系统
  • 页游传奇排行榜无锡seo优化公司
  • 广西南宁网站设计百度seo算法
  • 网站建设服务怎么样近期国内热点新闻事件
  • 阿里巴巴网站国际站建设seo托管服务
  • 企业网站优化之如何做需求分析网奇seo赚钱培训
  • 施工企业会计制度收入确认规定百度自然排名优化
  • 校园网站建设意义网络营销的特点有哪些
  • 内江做网站哪里便宜google搜索关键词热度
  • 福建省建设银行招聘网站网络推广员压力大吗
  • 动态网站订单怎么做搜索引擎优化营销
  • html5行业网站最近有哪些新闻
  • 做网站业务的怎么寻找客户在哪里打广告效果最好
  • 广东深圳seo服务内容
  • 做网站怎么备案网络服务有限公司
  • 网站主页特效欣赏百度官网下载电脑版
  • php mysql开发网站开发任何小说都能搜到的软件
  • the7 wordpress主题宁波seo外包费用
  • 云南建筑培训网seo刷点击软件
  • 男女做暖网站h5页面制作平台