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

实现Excel文件和其他文件导出为压缩包,并导入

导出

后端:

	@PostMapping("/exportExcelData")public void exportExcelData(HttpServletRequest request, HttpServletResponse response, @RequestBody ResData resData) throws IOException {List<Long> menuIds = resData.getMenuIds();List<Conversion> conversions = new ArrayList<>();List<String> ktrFilePaths = new ArrayList<>();for (Long menuId : menuIds) {Conversion conversion = conversionMapper.selectById(menuId);if (conversion != null) {conversions.add(conversion);String ktrFilePath = fileService.getKtrFilePathById(menuId);if (ktrFilePath != null && !ktrFilePaths.contains(ktrFilePath)) {ktrFilePaths.add(ktrFilePath);}}}// 创建Excel工作簿HSSFWorkbook workbook = new HSSFWorkbook();// 创建一个工作表Sheet sheet = workbook.createSheet("Conversions");// 创建单元格样式,并设置为文本格式CellStyle textStyle = workbook.createCellStyle();DataFormat format = workbook.createDataFormat();textStyle.setDataFormat(format.getFormat("@")); // "@" 表示文本格式// 创建标题行Row titleRow = sheet.createRow(0);// 创建单元格样式,并设置为文本格式titleRow.createCell(0).setCellValue("主键");titleRow.createCell(1).setCellValue("分组id");titleRow.createCell(2).setCellValue("名称");titleRow.createCell(3).setCellValue("备注");titleRow.createCell(4).setCellValue("创建人");titleRow.createCell(5).setCellValue("关联状态");titleRow.createCell(6).setCellValue("XMl");titleRow.createCell(7).setCellValue("创建时间");// 应用文本格式到标题行的特定单元格titleRow.getCell(0).setCellStyle(textStyle);titleRow.getCell(1).setCellStyle(textStyle);// 填充数据int rowNum = 1;for (Conversion conversion : conversions) {Row row = sheet.createRow(rowNum++);Cell cell = row.createCell(0);cell.setCellValue(String.valueOf(conversion.getId()));cell.setCellStyle(textStyle);cell = row.createCell(1);cell.setCellValue(String.valueOf(conversion.getGroupId()));cell.setCellStyle(textStyle); // 应用文本格式row.createCell(2).setCellValue(conversion.getName());row.createCell(3).setCellValue(conversion.getRemark());row.createCell(4).setCellValue(conversion.getCreateUserName());row.createCell(5).setCellValue(conversion.getState());row.createCell(6).setCellValue(conversion.getEditXml());row.createCell(7).setCellValue(String.valueOf(conversion.getCreateTime()));}// 设置响应头response.setContentType("application/vnd.ms-excel");response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("conversions.xls", "UTF-8"));// 设置响应头response.setContentType("application/zip");response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("conversions.zip", "UTF-8"));ZipOutputStream zipOut = new ZipOutputStream(response.getOutputStream());// 将Excel文件添加到压缩包ZipEntry excelEntry = new ZipEntry("conversions.xls");zipOut.putNextEntry(excelEntry);workbook.write(zipOut);zipOut.closeEntry();workbook.close();// 添加.ktr文件到ktr目录for (String filePath : ktrFilePaths) {File ktrFile = new File(filePath);if (ktrFile.exists()) {FileInputStream fis = new FileInputStream(ktrFile);// 创建ZipEntry时,需要包含ktr目录ZipEntry ktrEntry = new ZipEntry("ktr/" + ktrFile.getName());zipOut.putNextEntry(ktrEntry);byte[] bytes = new byte[1024];int length;while ((length = fis.read(bytes)) >= 0) {zipOut.write(bytes, 0, length);}fis.close();zipOut.closeEntry();}}// 完成压缩包zipOut.finish();zipOut.close();}

导出后的文件组成:

excel文件:

前端:

<template><div class="app-container" style="width:100%;"><el-form label-width="80px" label-position="left"><el-form-item label="模型树"><el-treeref="tree":data="treeData"show-checkbox:default-expand-all="false"node-key="id"highlight-current:props="defaultProps"/></el-form-item></el-form><div style="text-align: center;width:100%;"><el-button type="primary" @click="onSave">导出</el-button><el-button type="danger" @click="closePage">取消</el-button></div></div>
</template><script>
import { getTreeData } from '@/api/dataSchema'
import { exportData,exportExcelData } from '@/api/conversion'
import { Message } from 'element-ui'export default {name: 'Zzjg',inject: ['getList'],props: {proid: {type: String,required: true}},data() {return {defaultProps: {children: 'children',label: 'name'},treeData: []}},methods: {getDetailed() {const loading = this.$loading({lock: true,text: 'Loading',spinner: 'el-icon-loading',background: 'rgba(0, 0, 0, 0.7)'})getTreeData().then(response => {this.treeData = response.dataloading.close()}).catch(function() {loading.close()})},onSave() {var menuIds = this.$refs.tree.getCheckedKeys()if (menuIds.length === 0) {Message({message: '请选择要导出的模型',type: 'error',duration: 5 * 1000})return} else {const loading = this.$loading({lock: true,text: 'Loading',spinner: 'el-icon-loading',background: 'rgba(0, 0, 0, 0.7)'})exportExcelData({ menuIds: menuIds }).then(response => {var fileName = 'download.zip'const contentDisposition = response.headers['content-disposition']if (contentDisposition) {fileName = window.decodeURI(response.headers['content-disposition'].split('=')[1], 'UTF-8')}const blob = new Blob([response.data], {type: `application/zip` // word文档为msword,pdf文档为pdf})const objectUrl = URL.createObjectURL(blob)const link = document.createElement('a')link.href = objectUrllink.setAttribute('download', fileName)document.body.appendChild(link)link.click()// 释放内存window.URL.revokeObjectURL(link.href)Message({message: '导出成功',type: 'success',duration: 5 * 1000})loading.close()this.$emit('update:visible', false)this.getList()}).catch(response => {loading.close()})}},closePage() {this.$emit('update:visible', false)this.getList()}}
}
</script>

代码拆解:

通过前端传来的menuIds进行遍历,把每一条数据插到excel里面并且通过menuIds找到文件名与之对应的ktr文件放到文件夹中。

for (Long menuId : menuIds) {Conversion conversion = conversionMapper.selectById(menuId);if (conversion != null) {conversions.add(conversion);String ktrFilePath = fileService.getKtrFilePathById(menuId);if (ktrFilePath != null && !ktrFilePaths.contains(ktrFilePath)) {ktrFilePaths.add(ktrFilePath);}}}

创建excel导出模板:

// 创建Excel工作簿HSSFWorkbook workbook = new HSSFWorkbook();// 创建一个工作表Sheet sheet = workbook.createSheet("Conversions");// 创建单元格样式,并设置为文本格式CellStyle textStyle = workbook.createCellStyle();DataFormat format = workbook.createDataFormat();textStyle.setDataFormat(format.getFormat("@")); // "@" 表示文本格式// 创建标题行Row titleRow = sheet.createRow(0);// 创建单元格样式,并设置为文本格式titleRow.createCell(0).setCellValue("主键");titleRow.createCell(1).setCellValue("分组id");titleRow.createCell(2).setCellValue("名称");titleRow.createCell(3).setCellValue("备注");titleRow.createCell(4).setCellValue("创建人");titleRow.createCell(5).setCellValue("关联状态");titleRow.createCell(6).setCellValue("XMl");titleRow.createCell(7).setCellValue("创建时间");// 应用文本格式到标题行的特定单元格titleRow.getCell(0).setCellStyle(textStyle);titleRow.getCell(1).setCellStyle(textStyle);// 填充数据int rowNum = 1;for (Conversion conversion : conversions) {Row row = sheet.createRow(rowNum++);Cell cell = row.createCell(0);cell.setCellValue(String.valueOf(conversion.getId()));cell.setCellStyle(textStyle);cell = row.createCell(1);cell.setCellValue(String.valueOf(conversion.getGroupId()));cell.setCellStyle(textStyle); // 应用文本格式row.createCell(2).setCellValue(conversion.getName());row.createCell(3).setCellValue(conversion.getRemark());row.createCell(4).setCellValue(conversion.getCreateUserName());row.createCell(5).setCellValue(conversion.getState());row.createCell(6).setCellValue(conversion.getEditXml());row.createCell(7).setCellValue(String.valueOf(conversion.getCreateTime()));}

我这里的id和groupId位数特别长,所以对这两列做了默认为文本的处理,否则会变成科学计数法,会丢精。

具体如下:
 

// 创建单元格样式,并设置为文本格式CellStyle textStyle = workbook.createCellStyle();DataFormat format = workbook.createDataFormat();textStyle.setDataFormat(format.getFormat("@")); // "@" 表示文本格式// 应用文本格式到标题行的特定单元格titleRow.getCell(0).setCellStyle(textStyle);titleRow.getCell(1).setCellStyle(textStyle);Row row = sheet.createRow(rowNum++);Cell cell = row.createCell(0);cell.setCellValue(String.valueOf(conversion.getId()));cell.setCellStyle(textStyle);cell = row.createCell(1);cell.setCellValue(String.valueOf(conversion.getGroupId()));cell.setCellStyle(textStyle); // 应用文本格式

把excel文件添加到压缩包:

	// 将Excel文件添加到压缩包ZipEntry excelEntry = new ZipEntry("conversions.xls");zipOut.putNextEntry(excelEntry);workbook.write(zipOut);zipOut.closeEntry();workbook.close();

把ktr文件放到ktr命名的文件夹中,并关闭压缩文件流

// 添加.ktr文件到ktr目录for (String filePath : ktrFilePaths) {File ktrFile = new File(filePath);if (ktrFile.exists()) {FileInputStream fis = new FileInputStream(ktrFile);// 创建ZipEntry时,需要包含ktr目录ZipEntry ktrEntry = new ZipEntry("ktr/" + ktrFile.getName());zipOut.putNextEntry(ktrEntry);byte[] bytes = new byte[1024];int length;while ((length = fis.read(bytes)) >= 0) {zipOut.write(bytes, 0, length);}fis.close();zipOut.closeEntry();}}// 完成压缩包zipOut.finish();zipOut.close();

导出就完成了。

导入

后端

导入的时候有一个要求,就是把导出时的id作为老的id存到数据库里,并生成新的id把新的id作为对应ktr的文件名存到对应的路径下面

解析数据:

	@PostMapping("/insertData")public ResultData insertData(@RequestAttribute Long _userId, HttpServletRequest request) {MultipartHttpServletRequest req = (MultipartHttpServletRequest) request;MultipartFile uploadFile = req.getFile("uploadfile_ant");String originalName = uploadFile.getOriginalFilename();String docPath = "";List<Long> codes = new ArrayList<>(); // 用于存储所有导入的 IDtry {String classpath = ResourceUtils.getURL("classpath:").getPath();String path = classpath + File.separator + "static" + File.separator + "file" + File.separator + "yulan";docPath = path + File.separator + originalName;File dir = new File(path);if (!dir.exists()) {dir.mkdirs();}// 保存压缩文件File zipFile = new File(docPath);FileCopyUtils.copy(uploadFile.getInputStream(), new FileOutputStream(zipFile));// 解压压缩文件File unzipDir = new File(zipFile.getPath().substring(0, zipFile.getPath().lastIndexOf(".zip")));if (!unzipDir.exists()) {unzipDir.mkdirs();}unzipFile(zipFile, unzipDir);// 处理解压后的文件processUnzippedFiles(unzipDir);return ResultData.success("ok", codes); // 返回所有导入的 ID 列表} catch (Exception e) {e.printStackTrace();return ResultData.error("error");}}

解压代码:

private void unzipFile(File zipFile, File unzipDir) throws IOException {try (ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFile))) {ZipEntry entry = zipIn.getNextEntry();while (entry != null) {String filePath = unzipDir.getPath() + File.separator + entry.getName();if (!entry.isDirectory()) {extractFile(zipIn, filePath);} else {File dir = new File(filePath);dir.mkdirs();}zipIn.closeEntry();entry = zipIn.getNextEntry();}}}
	private void extractFile(ZipInputStream zipIn, String filePath) throws IOException {new File(filePath).getParentFile().mkdirs();try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath))) {byte[] bytesIn = new byte[4096];int read = 0;while ((read = zipIn.read(bytesIn)) != -1) {bos.write(bytesIn, 0, read);}}}

根据不同的文件类型去做不同的处理:

	private void processUnzippedFiles(File unzipDir) throws Exception {// 遍历解压后的目录,处理每个文件Files.walk(unzipDir.toPath()).forEach(filePath -> {try {if (Files.isRegularFile(filePath) && filePath.toString().endsWith(".xls")) {//如果是excel文件processExcelFile(filePath, unzipDir.toPath());
//						} else if (Files.isDirectory(filePath) && "ktr".equals(filePath.getFileName().toString())) {
//							//ktr文件夹
//							processKtrDirectory(filePath);}} catch (Exception e) {e.printStackTrace();}});}

处理excel:

@Transactionalpublic void processExcelFile(Path filePath, Path zipPath) throws Exception {Workbook workbook = null;try {FileInputStream excelFile = new FileInputStream(filePath.toFile());workbook = WorkbookFactory.create(excelFile); // 支持多种格式// 假设我们只处理第一个工作表Sheet sheet = workbook.getSheetAt(0);// 跳过标题行int startRowIndex = 1;DataFormatter formatter = new DataFormatter();for (int i = startRowIndex; i <= sheet.getLastRowNum(); i++) {Row row = sheet.getRow(i);if (row != null) {// 假设Excel文件的列顺序和数据库字段对应Cell idCell = row.getCell(0);Cell groupIdCell = row.getCell(1);Cell NameCell = row.getCell(2);Cell remarkCell = row.getCell(3);Cell creatorCell = row.getCell(4);Cell xmlCell = row.getCell(6);// 检查空值和数据转换String setOldId = formatter.formatCellValue(row.getCell(0));String groupId = formatter.formatCellValue(row.getCell(1));String remark = (remarkCell != null) ? remarkCell.getStringCellValue() : null;String Name = (NameCell != null) ? NameCell.getStringCellValue() : null;String creator = (creatorCell != null) ? creatorCell.getStringCellValue() :null;String state = formatter.formatCellValue(row.getCell(5));String XML = (xmlCell != null) ? xmlCell.getStringCellValue() : null;// 创建一个数据对象,例如DataObject,并填充字段Conversion conversion = new Conversion();conversion.setId(SnowflakeIdGenerator.getId());conversion.setOldId(Long.parseLong(setOldId));conversion.setGroupId(Long.parseLong(groupId));conversion.setName(Name);conversion.setRemark(remark);conversion.setCreateUserId(creator);conversion.setState(Integer.parseInt(state));conversion.setEditXml(XML);conversion.setCreateTime(LocalDateTime.now());// 保存到数据库conversionMapper.insert(conversion);//ktr文件夹processKtrDirectory(zipPath, conversion.getId(), conversion.getOldId());}}} catch (Exception e) {throw new Exception("Error processing Excel file", e);} finally {if (workbook != null) {try {workbook.close();} catch (IOException e) {// Log and handle workbook close exception}}}}

处理ktr:

private void processKtrDirectory(Path ktrDir, Long newId, Long oldId) throws Exception {// 处理ktr文件夹,将文件保存到磁盘路径下的逻辑// 例如:String targetPath = ktrPath + File.separator + Constant.kettleScriptFileName + File.separator + Constant.ktrFileName + File.separator;String newPath = ktrDir.toString()+"/ktr";try {Files.copy(Paths.get(newPath + File.separator + oldId.toString()), Paths.get(targetPath + newId.toString()));} catch (IOException e) {e.printStackTrace();}}

用copy(source,target)就可以实现把文件保存到指定路径

fileService.getKtrFilePathById:

/*** 根据menuId获取对应的.ktr文件路径。* @return 文件路径*/
@Service
@Transactional
public class FileServiceImpl implements FileService {@Value("${ktr.path}")private String ktrPath;public String getKtrFilePathById(Long menuId) {// 假设.ktr文件存储在 "/path/to/ktr/files/" 目录下,文件名为 "menuId.ktr"String baseDir = ktrPath + File.separator + Constant.kettleScriptFileName + File.separator + Constant.ktrFileName+File.separator;File file = new File(baseDir + menuId);if (file.exists()) {return file.getAbsolutePath();} else {return null; // 或者抛出一个异常,表示文件不存在}}
}

前端:

<template><div class="app-container" style="margin: 0 auto;width:100%;"><el-form ref="form" label-width="80px" label-position="left"><!-- <el-form-item><div slot="label">分组<font color="red">*</font></div><el-select v-model="form.groupId" placeholder="请选择分组" style="width: 100%"><el-option v-for="item in fzList" :key="item.id" :label="item.name" :value="item.id" /></el-select></el-form-item> --><!-- <el-form-item><div slot="label">模型名称<font color="red">*</font></div><el-input v-model="form.name" style="width:100%;" :autosize="{ minRows: 2, maxRows: 2}" /></el-form-item> --><el-form-item><div slot="label">导入模型<font color="red">*</font></div><el-uploadaccept=".zip"ref="upload"name="uploadfile_ant"class="upload-demo":limit="1":action="uploadpath":headers="uoloadheaders":before-upload="beforeAvatarUpload":on-success="handleAvatarSuccess":on-change="handleChange":on-remove="handleRemove":on-exceed="handleExceed":file-list="fileList"><el-button size="small" icon="el-icon-upload" type="primary">选择模型文件</el-button><span style="color:red;">  上传文件大小不能超过100MB</span></el-upload></el-form-item><!-- <el-form-item label="备注:"><el-input v-model="form.remark" type="textarea" maxlength="200" rows="6" placeholder="备注" /></el-form-item> --></el-form><!-- <div style="text-align: center;width:100%;"><el-button type="primary" @click="onSave">保存</el-button><el-button type="danger" @click="closePage">取消</el-button></div> --></div>
</template><script>
import { getWorkList } from '@/api/dataSchema'
import { updateData } from '@/api/conversion'import { Message, MessageBox } from 'element-ui'
import tool from '@/utils/tool'export default {name: 'Zzjg',inject: ['getList'],props: {proid: {type: String,required: true}},data() {return {uploadpath: '',uoloadheaders: {},fileData: '', // 文件上传数据(多文件合一)fileList: [], // upload多文件数组fzList: [],form: {},code: ''}},methods: {getDetailed() {getWorkList().then(response => {        this.fzList = response.datalet address = process.env.NODE_ENV == 'development' ? process.env.VUE_APP_URL_RECON : process.env.VUE_APP_BASE_API;var path = '/ltcloud/conversion/insertData'this.uploadpath = address + paththis.uoloadheaders = {'X-TOKEN' : tool.getCookie('X-Token'),'client-url':location.href,'applicationId':this.applicationId}})},handleAvatarSuccess(res, file) {if (res.code === 20000) {this.code = res.dataMessage({message: '上传成功',type: 'success',duration: 5 * 1000})} else {Message({message: res.msg,type: 'error',duration: 5 * 1000})}},// 移除handleRemove(file, fileList) {this.fileList = fileList},beforeAvatarUpload(file) {const isLt2M = file.size / 1024 / 1024 < 100if (!isLt2M) {this.$message.error('上传文件大小不能超过100MB!')}return isLt2M},// 选取文件超过数量提示handleExceed(files, fileList) {this.$message.warning(`当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`)},// 监控上传文件列表handleChange(file, fileList) {const existFile = fileList.slice(0, fileList.length - 1).find(f => f.name === file.name)if (existFile) {this.$message.error('当前文件已经存在!')fileList.pop()}this.fileList = fileList},onSave() {console.log('分组不能为空')if (!this.form.groupId) {this.$message.error('分组不能为空')return} else if (!this.form.name) {this.$message.error('模型名称不能为空')return} else if (this.fileList.length === 0) {this.$message.error('导入模型不能为空')return} else {const loading = this.$loading({lock: true,text: 'Loading',spinner: 'el-icon-loading',background: 'rgba(0, 0, 0, 0.7)'})this.form.idList = this.codeupdateData(this.form).then(response => {Message({message: '编辑成功',type: 'success',duration: 5 * 1000})loading.close()this.$emit('update:visible', false)this.getList()}).catch(response => {loading.close()this.getList()})}},closePage() {this.$emit('update:visible', false)this.getList()}}
}
</script><style lang="less">/deep/ .el-dialog {width: 550px;height: 650px;}.displayCol {display: flex;}.newNum {height: 20px;width: 20px;border: 1px solid #333;border-radius: 50%;text-align: center;margin-top: 3px;line-height: 20px;}/deep/.el-form-item__label {text-align: left !important;padding: 0 10px;}.disabled-text {pointer-events: none; /* 阻止鼠标事件 */cursor: default; /* 将鼠标光标设置为默认样式,表明文本不可点击 */opacity: 0.5; /* 降低文本的不透明度以显示出它是不可交互的 */user-select: none; /* 禁止文本被选中 */}.el-upload-list {float: left;margin: 0;padding: 0;list-style: none;}.el-upload {margin-left: 0px;display: inline-block;text-align: center;cursor: pointer;outline: 0;}.el-upload__tip {font-size: 12px;color: #606266;margin-top: 7px;width: 300px;line-height: 45px;height: 10px;}
</style>

相关文章:

实现Excel文件和其他文件导出为压缩包,并导入

导出 后端&#xff1a; PostMapping("/exportExcelData")public void exportExcelData(HttpServletRequest request, HttpServletResponse response, RequestBody ResData resData) throws IOException {List<Long> menuIds resData.getMenuIds();List<Co…...

Linux:基础开发工具

目录 软件包管理器yum 什么是软件包&#xff1f; 查看软件包 安装软件 卸载软件 vim vim的基本操作 gcc/g使用 预处理 编译 汇编 连接 make/Makefile .PHONY伪目标 定义使用变量 版本控制器Git 安装git git的使用 git add git commit git push git pull …...

【mac】终端左边太长处理,自定义显示名称(terminal路径显示特别长)

1、打开终端 2、步骤 &#xff08;1&#xff09;修改~/.zshrc文件 nano ~/.zshrc&#xff08;2&#xff09;添加或修改PS1&#xff0c;我是自定义了名字为“macminiPro” export PS1"macminiPro$ "&#xff08;3&#xff09;使用 nano: Ctrl o &#xff08;字母…...

嵌入式硬件设计:从概念到实现的全流程

嵌入式硬件设计是现代电子技术中一个至关重要的领域&#xff0c;涉及从硬件架构设计到硬件调试的各个方面。它为我们日常生活中的各类智能设备、家电、工业控制系统等提供了强大的支持。本文将介绍嵌入式硬件设计的基本流程、关键技术、常用工具以及常见的挑战和解决方案&#…...

【Nginx】核心概念与安装配置解释

文章目录 1. 概述2. 核心概念2.1.Http服务器2.2.反向代理2.3. 负载均衡 3. 安装与配置3.1.安装3.2.配置文件解释3.2.1.全局配置块3.2.2.HTTP 配置块3.2.3.Server 块3.2.4.Location 块3.2.5.upstream3.2.6. mine.type文件 3.3.多虚拟主机配置 4. 总结 1. 概述 Nginx是我们常用的…...

数据库-MySQL-MybatisPlus实战

文章目录 前言一、整合mybatis-plus二、CRUD操作1、insert操作2、update操作3、delete操作 三、条件构造器(Wrapper)QueryWrapperUpdateWrapperLambdaQueryWrapperLambdaUpdateWrapper 四、分页查询五、自定义主键生成器六、总结 前言 mybatis相信都不陌生&#xff0c;目前互联…...

Vue2学习记录

前言 这篇笔记&#xff0c;是根据B站尚硅谷的Vue2网课学习整理的&#xff0c;用来学习的 如果有错误&#xff0c;还请大佬指正 Vue核心 Vue简介 Vue (发音为 /vjuː/&#xff0c;类似 view) 是一款用于构建用户界面的 JavaScript 框架。 它基于标准 HTML、CSS 和 JavaScr…...

thinkphp中对请求封装

请求的封装 //调用 $res Http::post($this->baseUrl . $url,$params,[CURLOPT_HTTPHEADER > [Content-Type: application/json,Content-Length: . strlen($params),],]);<?php namespace fast; /*** 字符串类*/ class Http {/*** 发送一个POST请求*/public static …...

网络安全中的数据科学如何重新定义安全实践?

组织每天处理大量数据&#xff0c;这些数据由各个团队和部门管理。这使得全面了解潜在威胁变得非常困难&#xff0c;常常导致疏忽。以前&#xff0c;公司依靠 FUD 方法&#xff08;恐惧、不确定性和怀疑&#xff09;来识别潜在攻击。然而&#xff0c;将数据科学集成到网络安全中…...

通过指令导入/导出vscode扩展插件

导出扩展&#xff1a; 打开VSCode终端&#xff1a; 在VSCode中&#xff0c;你可以通过菜单栏的“终端”选项打开终端&#xff0c;或者使用快捷键Ctrl &#xff08;反引号&#xff0c;通常在键盘左上角&#xff09;。运行导出命令&#xff1a; 在终端中&#xff0c;输入以下命…...

vscode添加环境变量(mujoco)

文章目录 前言一、创建.env文件二、编写setting.jason 前言 之前一直用pycharm&#xff0c;最近改用cursor了&#xff0c;在pycharm中设置环境变量修改运行配置就行了&#xff0c;vscode要麻烦一些&#xff0c;记录一下。 一、创建.env文件 以mujoco环境变量为例&#xff0c;…...

0-1背包问题(1):贪心算法

问题&#xff1a; 有 n 个物品和背包的容量&#xff0c;每个物品的重量为 w[i]&#xff0c;价值为 v[i]&#xff0c;背包的容量为 W。选若干个物品放入购物车&#xff0c;物品不可分割&#xff0c;使价值最大。 问题分析&#xff1a; 首先考虑贪心策略&#xff1a; 每次挑选…...

Qt界面篇:QMessageBox高级用法

1、演示效果 2、用法注意 2.1 设置图标 用于显示实际图标的pixmap取决于当前的GUI样式。也可以通过设置icon pixmap属性为图标设置自定义pixmap。 QMessageBox::Icon icon(...

计算机操作系统——进程控制(Linux)

进程控制 进程创建fork&#xff08;&#xff09;函数fork() 的基本功能fork() 的基本语法fork() 的工作原理fork() 的典型使用示例fork() 的常见问题fork() 和 exec() 结合使用总结 进程终止与$进程终止的本质进程终止的情况正常退出&#xff08;Exit&#xff09;由于信号终止非…...

游戏引擎学习第23天

实时代码编辑功能的回顾 当前实现的实时代码编辑功能已经取得了显著的成功&#xff0c;表现出强大的性能和即时反馈能力。该功能允许开发者在修改代码后几乎立即看到变化在运行中的程序中体现出来&#xff0c;极大提升了开发效率。尽管目前的演示内容较为简单&#xff0c;呈现…...

0基础学java之Day25

Vector /** 知识点&#xff1a;Vector独有的方法 理解&#xff1a; * Vector在JDK1.0开始就已经存在 -- 元老级别的集合类&#xff0c; * 集合框架的概念是JDK1.2开始才有的&#xff0c; * 开发人员为了将Vector保留下来&#xf…...

android集成FFmpeg步骤以及常用命令,踩坑经历

1、入坑第一步:首先集成的库必须正确。最好是有ndk的,FFmpeg有许多个版本,我才开始接触的时候随便选了一个,一般的 方法没有问题。但是涉及到需要使用libx264等条件进行编码时,老是报错,网上搜索资料也没有人说需要ndk的支持才行。这个问题困扰了好几天,怎么试不行,最后…...

Mac——鼠标增强插件Mos

功能说明&#xff1a; 能够解决鼠标断续、不灵敏等鼠标问题。 下载地址&#xff1a; Mac——鼠标增强插件Mos...

【c++篇】:解读Set和Map的封装原理--编程中的数据结构优化秘籍

✨感谢您阅读本篇文章&#xff0c;文章内容是个人学习笔记的整理&#xff0c;如果哪里有误的话还请您指正噢✨ ✨ 个人主页&#xff1a;余辉zmh–CSDN博客 ✨ 文章所属专栏&#xff1a;c篇–CSDN博客 文章目录 前言一.set和map的初步封装1.树的节点封装修改2.Find()查找函数3.红…...

华为鸿蒙内核成为HarmonyOS NEXT流畅安全新基座

HDC2024华为重磅发布全自研操作系统内核—鸿蒙内核&#xff0c;鸿蒙内核替换Linux内核成为HarmonyOS NEXT稳定流畅新基座。鸿蒙内核具备更弹性、更流畅、更安全三大特征&#xff0c;性能超越Linux内核10.7%。 鸿蒙内核更弹性&#xff1a;元OS架构&#xff0c;性能安全双收益 万…...

ArcGIS API for Javascript学习

一、ArcGIS API for Javascript 介绍 ArcGIS API for Javascript 是由美国 Esri 公司推出&#xff0c;跟随ArcGIS 9.3 同时发布的&#xff0c;是Esri 基于dojo 框架和 REST 风格实现的一套编程接口。通过 ArcGIS API for Javascript可以对ArcGIS for Server 进行访问&#xff…...

LeetCode 3206.交替组 I:遍历

【LetMeFly】3206.交替组 I&#xff1a;遍历 力扣题目链接&#xff1a;https://leetcode.cn/problems/alternating-groups-i/ 给你一个整数数组 colors &#xff0c;它表示一个由红色和蓝色瓷砖组成的环&#xff0c;第 i 块瓷砖的颜色为 colors[i] &#xff1a; colors[i] …...

环形缓冲区

什么是环形缓冲区 环形缓冲区,也称为循环缓冲区或环形队列,是一种特殊的FIFO(先进先出)数据结构。它使用一块固定大小的内存空间来缓存数据,并通过两个指针(读指针和写指针)来管理数据的读写。当任意一个指针到达缓冲区末尾时,会自动回绕到缓冲区开头,形成一个"环"。…...

Maven 仓库

Maven 仓库对于管理构建 Java 项目所需的依赖和插件至关重要。 Maven 仓库主要有三种类型&#xff1a;本地仓库、中央仓库和远程仓库。 本文将探讨每种仓库的用途以及如何有效使用它们。 Maven 仓库类型 本地仓库 本地仓库是位于您本地机器上的一个目录&#xff0c;Maven 在…...

29.UE5蓝图的网络通讯,多人自定义事件,变量同步

3-9 蓝图的网络通讯、多人自定义事件、变量同步_哔哩哔哩_bilibili 目录 1.网络通讯 1.1玩家Pawn之间的同步 1.2事件同步 1.3UI同步 1.4组播 1.5变量同步 1.网络通讯 1.1玩家Pawn之间的同步 创建一个第三人称项目 将网络模式更改为监听服务器&#xff0c;即将房主作为…...

计算机网络习题解答--个人笔记(未完)

本篇文章为关于《计算机网络-自顶向下方法第七版》的阅读总结和课后习题解答(未完待续) 第二章&#xff1a; cookie&#xff1a;&#xff08;这里是比较老版本的HTTP&#xff0c;具体HTTPs是怎么实现的不是很清楚&#xff09;cookie的原理其实很简单。就是在HTTP消息头上又多…...

Unity图形学之雾Fog

1.设置雾化&#xff1a; 2.雾化变化曲线&#xff1a;FogMode &#xff08;1&#xff09;线性&#xff1a; &#xff08;2&#xff09;一次指数&#xff1a; &#xff08;3&#xff09;二次指数&#xff1a; Shader "Custom/FogTest" {Properties{_Color ("Color…...

ML 系列:第 36 节 — 统计学中的抽样类型

ML 系列&#xff1a;第 36 天 — 统计学中的抽样类型 文章目录 一、说明二、抽样方法三、简单随机抽样四、 Stratified Sampling分层抽样五、 Cluster Sampling 整群抽样六、Systematic Sampling系统抽样七、Convenience Sampling便利抽样八、结论 一、说明 统计学中的抽样类型…...

docker-compose部署java服务

文章目录 一、下载安装docker-compose二、编写Dockerfile文件三、编写docker-compose.yml文件配置说明 四、服务启动五、测试与验证 一、下载安装docker-compose 在安装docker时&#xff0c;并不会同时把docker-compose安装好&#xff0c;需要额外安装一下 下载docker-compos…...

ubuntu22开机自动登陆和开机自动运行google浏览器自动打开网页

一、开机自动登陆 1、打开settings->点击Users 重启系统即可自动登陆桌面 二、开机自动运行google浏览器自动打开网页 1、安装google浏览器 sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb sudo dpkg -i ./google-chrome-stable…...

java接口对接标准

概述 最近在跟许多外部平台对接&#xff0c;遇到了很多问题&#xff0c;在此记录一下接口的对接标准。 接口对接标准 确认环境&#xff0c;分别获取di和prd环境的接口信息&#xff0c;比如域名。确认不同环境的防火墙是否连通。接口校验&#xff0c;接口携带的token信息如何…...

训练的decoder模型文本长度不一致,一般设置为多大合适,需要覆盖最长的文本长度么

在训练解码器模型时,文本长度不一致是常见的情况,需要根据任务的特性和数据集的长度分布来设置合理的最大长度 (max_length)。以下是一些指导原则,帮助你设置合适的最大长度: 1. 是否需要覆盖最长文本长度 覆盖最长文本长度: 如果任务对完整性要求很高(例如生成数学公式、…...

安装MySQL服务

安装版本MySQL8的安装包 安装界面 在这里选择MySQL中的Server only 只安装服务器端 如果选择custom需要如下图 进入配置导向&#xff0c;点击ready to configure&#xff0c;点击next即可 采用默认形式 执行成功后&#xff0c;会出现自动选择项 点击next然后再点击Finish 启动…...

十二、正则表达式、元字符、替换修饰符、手势和对话框插件

1. 正则表达式 1.1 基本使用 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>Document</title&g…...

Unreal从入门到精通之如何绘制用于VR的3DUI交互的手柄射线

文章目录 前言实现方式MenuLaser实现步骤1.Laser和Cursor2.移植函数3.启动逻辑4.检测射线和UI的碰撞5.激活手柄射线6.更新手柄射线位置7.隐藏手柄射线8.添加手柄的Trigger监听完整节点如下:效果图前言 之前我写过一篇文章《Unreal5从入门到精通之如何在VR中使用3DUI》,其中讲…...

如何提升编程能力第二篇

如何提升编程能力2 1. 引言2. 掌握理论基础2.1 理解编程语言的核心2.2 数据结构与算法2.3 计算机基础与系统设计3.1 多写代码3.2 参与开源项目3.3 开发自己的项目 4. 提高代码质量4.1 代码风格与可读性4.2 测试驱动开发 1. 引言 编程是推动现代科技发展的核心技能&#xff0c;…...

【AI日记】24.11.26 聚焦 kaggle 比赛

【AI论文解读】【AI知识点】【AI小项目】【AI战略思考】【AI日记】 核心工作 1 内容&#xff1a;研究 kaggle 比赛时间&#xff1a;3 小时 核心工作 2 内容&#xff1a;学习 kaggle 比赛 Titanic - Machine Learning from Disaster时间&#xff1a;4 小时备注&#xff1a;这…...

计算机网络八股整理(一)

计算机网络八股文整理 一&#xff1a;网络模型 1&#xff1a;网络osi模型和tcp/ip模型分别介绍一下 osi模型是国际标准的网络模型&#xff0c;它由七层组成&#xff0c;从上到下分别是&#xff1a;应用层&#xff0c;表示层&#xff0c;会话层&#xff0c;传输层&#xff0c;…...

删除链表中的重复元素

删除链表中的重复元素 单链表的创建和使用删除链表中的重复元素 I题目描述解题思路代码实现 删除链表中的重复元素 II题目描述解题思路代码实现 单链表的创建和使用 使用vector结合单链表数据结构创建一个通用单链表。 #include <iostream> #include <vector>str…...

序列求和 牛客网

链接&#xff1a;登录—专业IT笔试面试备考平台_牛客网 来源&#xff1a;牛客网 题目描述 定义S(n) 12 22 … n2&#xff0c;输出S(n) % 1000000007。 注意&#xff1a;1 < n < 1e18。 输入描述: 多组输入&#xff0c;输入直到遇到EOF为止&#xff1b;第一行输…...

【Oracle11g SQL详解】 SELECT 语句的基础用法与示例

SELECT 语句的基础用法与示例 在 Oracle 11g 中&#xff0c;SELECT 语句是最常用的 SQL 语句&#xff0c;用于从数据库表中查询数据。本文将从语法结构、使用方法和常见示例出发&#xff0c;系统讲解 SELECT 语句的基础用法。 一、SELECT 语句的基本语法 SELECT 列名1, 列名2…...

编译以前项目更改在x64下面时报错:函数“PVOID GetCurrentFiber(void)”已有主体

win32下面编译成功&#xff0c;但是x64报错 1>GetWord.c 1>md5.c 这两个文件无法编译 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winnt.h(24125,1): error C2084: 函数“PVOID GetCurrentFiber(void)”已有主体 1>C:\Program Files (x…...

【小白学机器学习36】关于独立概率,联合概率,交叉概率,交叉概率和,总概率等 概念辨析的例子

目录 1 先说结论 2 联合概率 3 边缘概率 4 (行/列)边缘概率的和 总概率1 5 条件概率 5.1 条件概率的除法公式 5.2 条件概率和联合概率区别 1 先说结论 关于独立概率&#xff0c;联合概率&#xff0c;交叉概率&#xff0c;交叉概率和&#xff0c;总概率 类型含义 …...

如何使用 Tailwind CSS 构建响应式网站:详细指南

文章目录 前言一、安装 Tailwind CSS二、配置 Tailwind CSS三、使用 Tailwind CSS 构建响应式网站四、优化和部署结语 前言 在当今的数字时代&#xff0c;网站不仅需要在桌面浏览器上看起来出色&#xff0c;还需要在移动设备和平板电脑上提供一致的用户体验。响应式设计成为了…...

LabVIEW发动机热磨合试验台

在汽车发动机的研发和质量控制中&#xff0c;发动机热磨合试验是关键环节。它能够检验发动机在实际运行条件下的性能&#xff0c;及时发现异响、振动、漏油等潜在问题。通过搭建基于LabVIEW的高效测试平台&#xff0c;可以显著提高发动机的可靠性和使用寿命。下面介绍LabVIEW开…...

【GPT】力量训练是什么,必要吗,有可以替代的方式吗

什么是力量训练&#xff1f; 力量训练是一种通过抵抗力&#xff08;如重量、阻力带、自身体重等&#xff09;来刺激肌肉收缩&#xff0c;从而提高肌肉力量、耐力和体积的运动形式。它包括以下常见形式&#xff1a; 自由重量训练&#xff1a;使用哑铃、杠铃、壶铃等。固定器械…...

pikachu文件上传漏洞通关详解

声明&#xff1a;文章只是起演示作用&#xff0c;所有涉及的网站和内容&#xff0c;仅供大家学习交流&#xff0c;如有任何违法行为&#xff0c;均和本人无关&#xff0c;切勿触碰法律底线 目录 概念&#xff1a;什么是文件上传漏洞一、客户端check二、MIME type三、getimagesi…...

java hashCode() 详解

hashCode() 是 Java 中 Object 类 提供的一个重要方法&#xff0c;它在 Java 集合框架中扮演着关键角色&#xff0c;特别是在使用哈希表相关的集合&#xff08;如 HashMap、HashSet 和 Hashtable&#xff09;时。以下是对 hashCode() 方法的详解&#xff0c;包括概念、用法、规…...

鸿蒙学习自由流转与分布式运行环境-价值与架构定义(1)

文章目录 价值与架构定义1、价值2、架构定义 随着个人设备数量越来越多&#xff0c;跨多个设备间的交互将成为常态。基于传统 OS 开发跨设备交互的应用程序时&#xff0c;需要解决设备发现、设备认证、设备连接、数据同步等技术难题&#xff0c;不但开发成本高&#xff0c;还存…...

JavaWeb

JavaWeb 一、JavaWeb 是什么&#xff1f;二、JavaWeb 发展阶段三、JavaWeb 常用架构Servlet JSP 架构SSH 架构SSM 架构SpringBoot架构SpringCloud架构 四、JavaWeb 项目结构&#xff08;带web.xml的&#xff09;五、如何打包六、war包部署1. Tomcat 介绍2. Tomcat目录结构3. 开…...