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

springboot上传下载文件

@RequestMapping(“bigJson”)
@RestController
@Slf4j
public class TestBigJsonController {

@Resource
private BigjsonService bigjsonService;@PostMapping("uploadJsonFile")
public ResponseResult<Long> uploadJsonFile(@RequestParam("file")MultipartFile file){if (file.isEmpty()) {return ResponseResult.error();}try {Bigjson bigjson = new Bigjson();bigjson.setJsonFileName(file.getName());// 解析JSON文件ObjectMapper objectMapper = new ObjectMapper();JSONObject jsonObject = objectMapper.readValue(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8), JSONObject.class);bigjson.setJsonFile(jsonObject.toJSONString());//Long id = bigjsonService.uploadJsonFile(bigjson);// 返回成功响应return ResponseResult.success(id);} catch (IOException e) {log.error("上传错误");return ResponseResult.error();}
}@GetMapping("/downloadJson")
public ResponseEntity<byte[]> downloadJson(@RequestParam("id") Long id){Bigjson bigjson = bigjsonService.getById(id);byte[] bytes = bigjson.getJsonFile().getBytes();// 设置响应头HttpHeaders headers = new HttpHeaders();headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename="+bigjson.getJsonFileName()+".json");headers.add("Cache-Control", "no-cache, no-store, must-revalidate");headers.add("Pragma", "no-cache");headers.add("Expires", "0");// 返回响应return new ResponseEntity<>(bytes, headers, HttpStatus.OK);}

}

http://www.lryc.cn/news/487235.html

相关文章:

  • Python学习从0到1 day29 Python 高阶技巧 ⑦ 正则表达式
  • 机器学习-web scraping
  • 移远通信5G RedCap模组RG255C-CN通过中国电信5G Inside终端生态认证
  • Javaweb梳理17——HTMLCSS简介
  • 【Android、IOS、Flutter、鸿蒙、ReactNative 】自定义View
  • win11跳过联网激活步骤
  • 利用c语言详细介绍下冒泡排序
  • C# 面向对象
  • android wifi扫描的capability
  • datawhale 2411组队学习:模型压缩4 模型量化理论(数据类型、int8量化方法、PTQ和QWT)
  • 数据分析-48-时间序列变点检测之在线实时数据的CPD
  • POD-Transformer多变量回归预测(Matlab)
  • Hadoop生态圈框架部署(七)- MySQL安装与配置教程
  • 视频直播5G CPE解决方案:ZX7981PG/ZX7981PMWIFI6网络覆盖
  • 技术周刊 |Google 2024 年首届 Web AI 峰会回顾
  • web——upload-labs——第十二关——%00截断
  • ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值。ojdbc8版本23.2.0.0驱动BUG【已解决】
  • win10 自带 directx 修复工具怎么用?最新 directx 修复工具使用方法介绍
  • 报错java: java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not ...解决方法
  • 前端三大件之CSS
  • C语言 | 指针 | 野指针 | 数组指针 | 指针数组 | 二级指针 | 函数指针 | 指针函数
  • mysql 的乐观锁和 mvcc 是一回事吗
  • redis的击穿和雪崩
  • java中创建多线程的4种方式
  • MATLAB深度学习(二)——如何训练一个卷积神经网路
  • 删除k8s 或者docker运行失败的脚本
  • 重置docker版本的octoprint管理员账号密码
  • prometheus监控数据远程写入Kafka集群
  • Excel使用-弹窗“此工作簿包含到一个或多个可能不安全的外部源的链接”的发生与处理
  • C++小白实习日记——Day 2 TSCNS怎么读取当前时间