Excel操作之工具类

需求:根据指定的路径下模版进行解析 将模版上传到指定的文件服务器。
1:将路径下的excel文件进行解析 下载

A:创建excel表格对应的字段注解 ExcelColumn

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ExcelColumn {
    int index() default -1; // 列的索引,从0开始

    String name() default ""; // 列名,可以与Excel中的标题对应

}

B:建立一个excel映射的实体对象

@ExcelColumn(index = 1, name = "A")
private String A;
@ExcelColumn(index = 2, name = "B")
private String B;

上述的属性A B的index对应excel的标题头的第几列的字段值
C:为了方便后续解析任意的excel文件 故创建一个文件解析工具 ExcelParserUtil.java

/**
     * excel解析工具类
     *
     * @param inputStream
     * @param clazz
     * @param <T>
     * @return
     */
    public static <T> List<T> parseExcel(InputStream inputStream, Class<T> clazz) throws Exception {
        List<T> result = new ArrayList<>();
        List<String> failReasonList = new ArrayList<>();
        int execRow = 1;
        try (Workbook workbook = new XSSFWorkbook(inputStream)) {
            Sheet sheet = workbook.getSheetAt(0); //第一个工作表
            Row headerRow = sheet.getRow(0); //第一行是标题行
            // 读取实体类的字段注解,构建字段名和列索引的映射
            Map<String, Integer> fieldIndexMap = new HashMap<>();
            Field[] fields = clazz.getDeclaredFields();
            for (Field field : fields) {
                ExcelColumn excelColumn = field.getAnnotation(ExcelColumn.class);
                if (excelColumn != null && excelColumn.index() >= 0) {
                    field.setAccessible(true);
                    fieldIndexMap.put(field.getName(), excelColumn.index());
                }
            }

            // 跳过标题行,从第二行开始解析数据
            for (int i = 1; i <= sheet.getLastRowNum(); i++) {
                Row row = sheet.getRow(i);
                T instance = clazz.getDeclaredConstructor().newInstance();
                for (Map.Entry<String, Integer> entry : fieldIndexMap.entrySet()) {
                    try {
                        String fieldName = entry.getKey();
                        int columnIndex = entry.getValue();
                        Cell cell = row.getCell(columnIndex);
                        if (cell != null) {
                            Field field = clazz.getDeclaredField(fieldName);
                            setFieldValue(instance, field, cell);
                        }
                    } catch (Exception e) {
                        failReasonList.add("第" + execRow + "行解析错误:" + e.getMessage());
                    }
                }
                execRow++;
                result.add(instance);
            }
        } catch (Exception e) {
            throw new Exception("parseExcel->数据解析错误:", e);
        }
        if (CollectionUtils.isNotEmpty(failReasonList)) {
            throw new Exception(JSON.toJSONString(failReasonList.subList(0, failReasonList.size() > 20 ? 20 : failReasonList.size())));
        }
        return result;
    }
/**
     * 方法setFieldValue 主要用于给每个单元格进行设置对应的值。
     * @param instance
     * @param field
     * @param cell
     * @throws IllegalAccessException
     * @throws InvocationTargetException
     */

    private static void setFieldValue(Object instance, Field field, Cell cell) throws IllegalAccessException, InvocationTargetException {
        Class<?> fieldType = field.getType();
        field.setAccessible(true);
        // 总是将Cell设置为STRING类型,以确保我们可以获取字符串值
        cell.setCellType(CellType.STRING);
        String cellValue = cell.getStringCellValue();
        if (String.class.equals(fieldType)) {
            field.set(instance, cell.getStringCellValue());
        } else if (Integer.class.equals(fieldType) || int.class.equals(fieldType)) {
            field.setInt(instance, Integer.parseInt(cellValue));
        } else if (Long.class.equals(fieldType) || long.class.equals(fieldType)) {
            field.setLong(instance, Long.parseLong(cellValue));
        } else if (Double.class.equals(fieldType) || double.class.equals(fieldType)) {
            field.setDouble(instance, Double.parseDouble(cellValue));
        } else if (Boolean.class.equals(fieldType) || boolean.class.equals(fieldType)) {
            field.setBoolean(instance, Boolean.parseBoolean(cellValue));
        } else {
            throw new RuntimeException("Unsupported field type: " + fieldType.getName());
        }
    }

  /**
     * 指定下载的文件路径 将文件流保存到执行的的位置
     *
     * @param url
     * @param savePath
     * @return
     */
    public static String download(String url, String savePath) {
        InputStream inputStream = null;
        FileOutputStream fos = null;
        try {
            URL u = new URL(url);
            HttpURLConnection conn = (HttpURLConnection) u.openConnection();
            //设置超时间为3秒
            conn.setConnectTimeout(HTTP_CONNECT_TIMEOUT);
            //防止屏蔽程序抓取而返回403错误
            conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
            //得到输入流
            inputStream = conn.getInputStream();
            //获取自己数组
            byte[] getData = readInputStream(inputStream);
            File file = new File(savePath);
//            文件保存位置
            createDir(file);
            fos = new FileOutputStream(file);
            fos.write(getData);
        } catch (IOException e) {
        } finally {
            try {
                if (fos != null) {
                    fos.close();
                }
                if (inputStream != null) {
                    inputStream.close();
                }
            } catch (IOException e) {
            }
        }
        return savePath;
    }


  /**
     * 从输入流中获取字节数组
     *
     * @param inputStream
     * @return
     * @throws IOException
     */
    private static byte[] readInputStream(InputStream inputStream) throws IOException {
        byte[] buffer = new byte[1024];
        int len = 0;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        while ((len = inputStream.read(buffer)) != -1) {
            bos.write(buffer, 0, len);
        }
        bos.close();
        return bos.toByteArray();
    }


 /**
     * 根据文件创建目录
     *
     * @param file
     */
    public static void createDir(File file) {
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
    }

D:使用上述工具类进行文件的解析和下载功能演练

//下载路径
    private static final String downloadUrl = "https://xxx.com.cn/files/";
    //模版位置
    private static final String templateUrl = "E:/source";
    //下载文件存放位置
    private static final String saveUrl = "E:/source/downlod";
    private static final String handCompany = "1-A.xlsx";
    private static final String company = "2-B.xlsx";
    private static final String industry = "3-C.xlsx";

public static void main(String[] args) {
        ExcelParserUtil parser = new ExcelParserUtil();
        try {
            File file = new File(templateUrl); // 替换为你的文件路径
            File[] files = file.listFiles();
            for (File fileItem : files) {
                if (fileItem.isFile()) {
                    InputStream inputStream = new FileInputStream(fileItem);
                    if (inputStream != null) {
                        String fileName = fileItem.getName();
                        List<ExcelEntity> excelEntities = parser.parseExcel(inputStream, ExcelEntity.class);
                        exec(excelEntities, parser, fileName);
                    }
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

private static void exec(List<ExcelEntity> entityList, ExcelParserUtil parser, String fileName) {
        List<String> list = new ArrayList<>();
        // 输出解析结果
        System.out.println("解析了数据:" + entityList.size());
        for (ExcelEntity entity : entityList) {
            //得到解析的文件数据做自己的业务逻辑处理。
            String finalUrl = downloadUrl + fileUrl;
            //处理投资池证券导入模板文件路径字段
            String download = parser.download(finalUrl, saveUrl + File.separator + "新的文件名称");
         
        }
    }

2:上传文件到执行服务器

/**
	 * 上传文件
	 * @param filePath
	 * @param typeId
	 * @return
	 */
	public static R upload(String filePath, String typeId) {
		
		CloseableHttpClient httpClient = HttpClientBuilder.create().build();
		CloseableHttpResponse httpResponse = null;
		RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(200000).setSocketTimeout(200000000).build();
		HttpPost httpPost = new HttpPost(baseUrl + PREFIX + "/service/files/upload");
		httpPost.setConfig(requestConfig);
		MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create().setMode(HttpMultipartMode.RFC6532);
		multipartEntityBuilder.setCharset(Charset.forName("UTF-8"));
		File file = new File(filePath);
		if (FrameStringUtil.isNotEmpty(typeId)) {
			multipartEntityBuilder.addPart("typeId", new StringBody(typeId, ContentType.create("text/plain", Consts.UTF_8)));
		}
		
	
		HttpEntity httpEntity = multipartEntityBuilder.build();
		httpPost.setEntity(httpEntity);

		try {
			httpResponse = httpClient.execute(httpPost);
			HttpEntity responseEntity = httpResponse.getEntity();
			int statusCode= httpResponse.getStatusLine().getStatusCode();
			if(statusCode == 200) {
				BufferedReader reader = new BufferedReader(new InputStreamReader(responseEntity.getContent()));
				StringBuffer buffer = new StringBuffer();
				String str = "";
				while(FrameStringUtil.isNotEmpty(str = reader.readLine())) {
					buffer.append(str);
				}

				String result = buffer.toString();
				R.setBody(result);
				R.setSucc();
				
				
				//post(url, params);
			}
			httpClient.close();
			if(httpResponse != null) {
				httpResponse.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
			R.setCode(-1001);
			R.setMessage("上传文件到文件管理服务失败: " + e.getMessage());
		}
		return R;
	}

3:文件基础相关操作

/**
     * 删除指定零时目录下的文件
     *
     * @param sourceUrl
     * @param destinationUrl
     * @param fileName
     * @return
     */
public static Boolean deleteFilesInDirectory(String tempUrl) {
        Boolean delFlag = false;
        File directory = new File(tempUrl);
        if (directory.exists() && directory.isDirectory()) {
            File[] files = directory.listFiles();
            if (files != null) {
                for (File file : files) {
                    if (file.isFile()) {
                        file.delete();
                        delFlag = true;
                        log.info("Deleted file: {}", file.getName());
                    }
                }
            } else {
                log.info("The directory is empty.....");
                delFlag = false;
            }
        } else {
            delFlag = false;
            log.info("The directory does not exist or is not a directory.");
        }
        return delFlag;
    }
/**
     * 将byte[]转成File
     *
     * @param sourceUrl
     * @param destinationUrl
     * @param fileName
     * @return
     */
    public static File byteToFile(byte[] bytes, String path, String name) throws IOException {
        File dir = new File(path);
        if (!dir.exists() && !dir.isDirectory()) {//判断文件目录是否存在
            dir.mkdirs();
        }

        File file = new File(path + File.separator + name);
        FileOutputStream fout = new FileOutputStream(file);
        BufferedOutputStream bout = new BufferedOutputStream(fout);
        bout.write(bytes);
        return file;
    }
 /**
     * 文件复制转移
     *
     * @param sourceUrl
     * @param destinationUrl
     * @param fileName
     * @return
     */
    public static String copyFile(String sourceUrl, String destinationUrl, String fileName) {
        String fileTempUrl = "";
        File sourceFile = new File(sourceUrl);
        fileTempUrl = destinationUrl + File.separator + fileName;
        File destinationFile = new File(fileTempUrl);
        try {
            FileUtils.copyFile(sourceFile, destinationFile);
            log.info("文件复制成功!");
        } catch (IOException e) {
            log.info("文件复制失败!");
            System.out.println("文件复制失败!" + e.getMessage());
        }
        return fileTempUrl;
    }

4:文件相关操作工具类

/**
	 * 创建指定路径的文件夹[不存在,则创建]
	 * @param destDirName
	 */
	public static void createDir(String destDirName) {
		File dir = new File(destDirName);
		if(dir.exists()) {
			LOGGER.info("目录" + destDirName + "已存在!");
		} else {
			if(!destDirName.endsWith(File.separator)) {
				destDirName = destDirName + File.separator;
			}
			//创建目录
			dir.mkdirs();
		}
	}
/**
	 * 读取文件[不存在,则创建]
	 * @param destFileName 文件名
	 * @return 创建成功返回true,否则返回false
	 * @throws IOException
	 */
	public static File readFile(String destFileName) throws IOException {
		File file = new File(destFileName);
		if (file.exists()) {
			//LOGGER.info("目标文件已存在: " + destFileName);
			return file;
		}
		if (!file.getParentFile().exists()) {
			if (!file.getParentFile().mkdirs()) {
				LOGGER.info("创建目录文件所在的目录失败!");
			}
		}
		//创建目标文件
		if (file.createNewFile()) {
			LOGGER.info("创建单个文件成功: " + destFileName);
		} else {
			LOGGER.info("创建单个文件失败: " + destFileName);
		}
		return file;
	}
/**
	 * 读取文件为byte[]
	 * @param destFileName
	 * @return
	 */
	public static byte[] readFileBytes(String destFileName) {
		try {
			BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(destFileName));
			int len = bufferedInputStream.available();
			byte[] bytes = new byte[len];
			int r = bufferedInputStream.read(bytes);
			if (len != r) {
				bytes = null;
				LOGGER.error("读取文件不正确");
			}
			bufferedInputStream.close();
			return bytes;
		} catch (FileNotFoundException e) {
			LOGGER.error(e.getMessage(), e);
		}
		catch (IOException e) {
			LOGGER.error(e.getMessage(), e);
		}
		return null;
	}
/**
	 * 根据目录获取下面为指定文件名的文件
	 * @param dir
	 * @param filename
	 * @return
	 */
	public static List<String> getFiles(String dir, String filename) {
		List<String> list = new ArrayList<String>();
		Map<String, List<String>> map = getDirFile(dir, true);
		List<String> allList = map.get("files");
		if(allList == null) {
			list = new ArrayList<String>();
		} else {
			for (String string : allList) {
				if(string.endsWith(File.separator + filename)) {
					list.add(string);
				}
			}
		}
		return list;
	}
/**
	 * 获取目录下的文件和文件夹
	 * @param dir
	 * @param isRecursion	是否递归,true是 false否
	 * @return {"files":["文件地址",""],"dirs":["目录地址",""]}
	 */
	public static Map<String, List<String>> getDirFile(String dir, boolean isRecursion) {
		Map<String, List<String>> map = new HashMap<String, List<String>>();
		File file = new File(dir);
		getDirFileDtl(file, map, isRecursion);
		return map;
	}
/*
	 * 获取目录的指定内容
	 * @param file
	 * @param map
	 */
	private static void getDirFileDtl(File file, Map<String, List<String>> map, boolean isRecursion) {
		File[] t = file.listFiles();
		if(t == null) {
			return;
		}
		for(int i = 0; i < t.length; i++){
			//判断文件列表中的对象是否为文件夹对象,如果是则执行tree递归,直到把此文件夹中所有文件输出为止
			if(t[i].isDirectory()) {
				List<String> dirs = map.get("dirs");
				if(dirs == null) {
					dirs = new ArrayList<String>();
				}
				dirs.add(t[i].getAbsolutePath());
				//System.out.println(t[i].getAbsolutePath()+"\n");
				map.put("dirs", dirs);
				if(isRecursion) {
					getDirFileDtl(t[i], map, isRecursion);
				}
			} else{
				List<String> files = map.get("files");
				if(files == null) {
					files = new ArrayList<String>();
				}
				files.add(t[i].getAbsolutePath());
				//System.out.println(t[i].getAbsolutePath()+"\n");
				map.put("files", files);
				getDirFileDtl(t[i], map, isRecursion);
			}
		}
	}

/**
	 * 读取http地址的文件到指定位置
	 * @param url
	 * @param savePath
	 * @param saveName
	 * @return
	 */
	public static File readFile(String url, String savePath, String saveName) {
		try {
			//new一个URL对象
			URL u = new URL(url);
			//打开链接
			HttpURLConnection conn = (HttpURLConnection)u.openConnection();
			//设置请求方式为"GET"
			conn.setRequestMethod("GET");
			//超时响应时间为5秒
			conn.setConnectTimeout(5 * 1000);
			//通过输入流获取图片数据
			InputStream inStream = conn.getInputStream();
			//得到图片的二进制数据,以二进制封装得到数据,具有通用性
			byte[] data = readFileBytes(inStream);

			//new一个文件对象用来保存图片,默认保存当前工程根目录
			createDir(savePath);
			File file = new File(savePath + saveName);
			if(file.exists()) {
				file.delete();
			}
			file = new File(savePath + saveName);
			//创建输出流
			FileOutputStream outStream = new FileOutputStream(file);
			//写入数据
			outStream.write(data);
			//关闭输出流
			outStream.close();
			return file;
		} catch (IOException e) {
			LOGGER.error("读取异常", e);
		}
		return null;
	}

/**
     * 创建ZIP文件
     * @param sourcePath 文件或文件夹路径
     * @param zipPath 生成的zip文件存在路径(包括文件名)
     */
    public static boolean createZip(String sourcePath, String zipPath) {
        FileOutputStream fos = null;
        ZipOutputStream zos = null;
        try {
            fos = new FileOutputStream(zipPath);
            zos = new ZipOutputStream(fos);
            writeZip(new File(sourcePath), "", zos);
        } catch (FileNotFoundException e) {
        	LOGGER.error("创建ZIP文件失败", e);
        	return false;
        } finally {
            try {
                if (zos != null) {
                    zos.close();
                }
            } catch (IOException e) {
            	LOGGER.error("创建ZIP文件失败",e);
            }

        }
        return true;
    }
private static void writeZip(File file, String parentPath, ZipOutputStream zos) {
        if(file.exists()){
            if(file.isDirectory()){//处理文件夹
                parentPath+=file.getName()+File.separator;
                File [] files=file.listFiles();
                for(File f:files){
                    writeZip(f, parentPath, zos);
                }
            }else{
                FileInputStream fis=null;
                DataInputStream dis=null;
                try {
                    fis=new FileInputStream(file);
                    dis=new DataInputStream(new BufferedInputStream(fis));
                    ZipEntry ze = new ZipEntry(parentPath + file.getName());
                    zos.putNextEntry(ze);
                    byte [] content=new byte[1024];
                    int len;
                    while((len=fis.read(content))!=-1){
                        zos.write(content,0,len);
                        zos.flush();
                    }

                } catch (FileNotFoundException e) {
                    LOGGER.error("创建ZIP文件失败",e);
                } catch (IOException e) {
                	LOGGER.error("创建ZIP文件失败",e);
                }finally{
                    try {
                        if(dis!=null){
                            dis.close();
                        }
                    }catch(IOException e) {
                    	LOGGER.error("创建ZIP文件失败",e);
                    }
                }
            }
        }
    }    
/**
	 * 公用下载文件<br>
	 * frame 返回路径和文件名称
	 * 		fileName:下载文件的名称
	 * 		downloadPath:下载文件的路径
	 * @param request
	 * @param response
	 * @param frame
	 * @throws IOException 
	 */
	public void download(HttpServletRequest request, HttpServletResponse response,
			String fileName, String downloadPath) throws IOException {
		response.setContentType("text/html;charset=UTF-8");
		try {
			request.setCharacterEncoding("UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		BufferedInputStream bis = null;
		BufferedOutputStream bos = null;
		
		if(FrameStringUtil.isEmpty(fileName) || FrameStringUtil.isEmpty(downloadPath)) {
			return;
		}

		long fileLength = new File(downloadPath).length();
		response.setHeader("Content-disposition", "attachment; filename=" + new String(fileName.getBytes("utf-8"),"iso-8859-1"));
		response.setHeader("Content-Length", String.valueOf(fileLength));

		bis = new BufferedInputStream(new FileInputStream(downloadPath));
		bos = new BufferedOutputStream(response.getOutputStream());
		byte[] buff = new byte[2048];
		int bytesRead;
		while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
			bos.write(buff, 0, bytesRead);
		}
		bis.close();
		bos.close();
	}

以上的是Excel操作之工具类 若需完整代码 可识别二维码后 给您发代码。
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/610768.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

milvus元数据在etcd的存储解析

milvus元数据在etcd的存储解析 数据以key-value形式存在。 大致包含如下一些种类: databasecollectionfieldpartitionindexsegment-indexresource_groupsession database 创建一个数据库会产生2个key&#xff0c;但value是相同的。 key规则: 前缀/root-coord/database/db…

【SRC实战】利用APP前端加密构造数据包

挖个洞先 https://mp.weixin.qq.com/s/ZnaRn222xJU0MQxWoRaiJg “ 以下漏洞均为实验靶场&#xff0c;如有雷同&#xff0c;纯属巧合” 01 — 漏洞证明 “ 参数加密的情况&#xff0c;不会逆向怎么办&#xff1f;” 1、新用户首次设置密码时抓包&#xff0c;此处设置为0000…

设计合理的IT运维服务目录:打造高效运维的蓝图

在数字化转型的浪潮中&#xff0c;一个设计合理、内容详尽的IT运维服务目录是连接服务提供者与消费者之间的桥梁&#xff0c;它不仅体现了服务设计的专业性&#xff0c;还直接影响着运维效率和服务质量。如何设计出既合理又高效的IT运维服务目录&#xff1f;让我们结合ITIL 4框…

Modown9.1主题无限制使用+Erphpdown17.1插件

Modown9.1主题无限制使用 1、Erphpdown17.1插件Modown9.1主题 2、送Modown主题详细教程。 1、Erphpdown插件和Modown主题无需激活 2、送的插件均无需激活 3、主题插件均不包更新 4、已亲测可以完美使用。 功能强大&#xff0c;适用于绝大多数虚拟资源站&#xff01;物超所值&a…

分布式光伏管理平台功能介绍

一、项目管理系统 1、关键信息&#xff1a;板块化展现项目关键信息&#xff0c;包含所在区域、屋面类型、未来25年发电量、累计收益等信息。 (1) 可迅速获取项目核心要点 (2) 及时跟进修改&#xff0c;凸显项目信息 (3) 项目信息清晰展现&#xff0c;了解整体项目流程 2、项…

【已解决】QT C++中QLineEdit不可粘贴输入

本博文源于生产实际&#xff0c;主要解决LineEdit不可粘贴输入的情况。下面将进行具体分析 问题来源 输入框只能一个个输入&#xff0c;不可复制粘贴。 分析 给QLineEdit装一个监听事件&#xff0c;监听它的事件即可。 问题解决步骤 问题一共分为三步&#xff1a; 书写监…

Find My资讯|苹果设备在修复期间可以保持启用“Find My“功能

iOS 17.5 中有一项名为"维修状态"的新功能&#xff0c;可让送修的设备保持启用"查找我的"&#xff08;Find My&#xff09;功能。此前&#xff0c;用户在送修设备时必须禁用跟踪设备位置的"查找我的"功能&#xff0c;但iOS 17.5发布后&#xff0…

鸿蒙应用开发DevEco Studio工程目录模块介绍

面向开发者&#xff0c;HarmonyOS 推出了 DevEco Studio 和 Dev Device Tool 两款开发工具&#xff0c;前者目前迭代至 3.1 版本&#xff08;对外开放版本&#xff09;&#xff0c;用于开发 HarmonyOS 应用&#xff1b;后者用于开发智能设备 应用的工程主体结构如上图 在这里我…

flutter开发实战-GetX响应式状态管理使用

flutter开发实战-GetX响应式状态管理使用 GetX是一个简单的响应式状态管理解决方案。GetX是Flutter的一款超轻、功能强大的解决方案。它将高性能状态管理、智能依赖注入和路由管理快速而实用地结合在一起。这里简单使用一下GetX 一、引入GetX 在工程的pubspec.yaml中引入插件…

Python中的分布式爬虫系统Scrapy与分布式任务队列的结合

随着互联网的不断发展&#xff0c;网络爬虫在数据采集和信息挖掘中发挥着重要作用。然而&#xff0c;单机爬虫往往难以应对大规模数据抓取的需求&#xff0c;因此&#xff0c;构建分布式爬虫系统成为了一种必然选择。本文将介绍如何利用 Python 中的 Scrapy 框架和分布式任务队…

TikTok自动评论、回复的脚本怎么制作?

在当今数字化的时代&#xff0c;社交媒体平台如TikTok已经成为人们日常生活的一部分&#xff0c;为了更有效地在TikTok上进行营销或互动&#xff0c;许多用户和企业开始寻找自动化工具&#xff0c;如自动评论和回复的脚本&#xff0c;以节省时间并提高效率。 本文将科普如何制…

H5 处理点击元素高亮、自定义按钮、去除焦点边框

1、设置移动设备上点击元素时出现的高亮颜色 *{-webkit-tap-highlight-color: transparent; }2、如果你想要自定义按钮的样式&#xff0c;你可以使用 -webkit-appearance: none; 来移除按钮的默认样式 .button {-webkit-appearance: none;appearance: none; /* 兼容性更好的通…

C语言 | Leetcode C语言题解之第72题编辑距离

题目&#xff1a; 题解&#xff1a; static inline int Min(const int a, const int b, const int c) {int min (a < b) ? a : b;return (min < c) ? min : c; }int minDistance(char * word1, char * word2){int m strlen(word1), n strlen(word2);int dp[m 1][n…

知识蒸馏,需要合适的教师模型,学生模型,蒸馏数据,损失函数,训练策略,让小模型有大模型的知识

知识蒸馏使用的是Teacher—Student模型&#xff0c;其中teacher是“知识”的输出者&#xff0c;student是“知识”的接受者。知识蒸馏的过程分为2个阶段: 原始模型训练: 训练"Teacher模型", 它的特点是模型相对复杂&#xff0c;也可以由多个分别训练的模型集成而成。…

C++_红黑树的学习

1. 红黑树的概念 红黑树 &#xff0c;是一种 二叉搜索树 &#xff0c;但 在每个结点上增加一个存储位表示结点的颜色&#xff0c;可以是 Red 或 Black 。 通过对 任何一条从根到叶子的路径上各个结点着色方式的限制&#xff0c;红黑树确保没有一条路 径会比其他路径长出俩倍 &…

【活动】如何通过AI技术提升内容生产的效率与质量

&#x1f308;个人主页: 鑫宝Code &#x1f525;热门专栏: 闲话杂谈&#xff5c; 炫酷HTML | JavaScript基础 ​&#x1f4ab;个人格言: "如无必要&#xff0c;勿增实体" 文章目录 如何通过AI技术提升内容生产的效率与质量引言一、自然语言处理&#xff08;NLP&…

JAVA排序相关习题7

1.插入排序 1.1 基本思想 直接插入排序是一种简单的插入排序法&#xff0c;其基本思想是&#xff1a; 把待排序的记录按其关键码值的大小逐个插入到一个已经排好序的有序序列中&#xff0c;直到所有的记录插入完为止&#xff0c;得到一个新的有序序列 。 /*** 时间复杂度&…

自然资源-地质勘查工作的流程梳理

自然资源-地质勘查工作的流程梳理 地质勘查从广义上可理解为地质工作&#xff0c;地质队员就好像是国家宝藏的“寻宝人”&#xff0c;通过地质勘查&#xff0c;为国家找矿&#xff0c;以保障国家能源资源安全和服务国计民生&#xff0c;发挥着地质工作在国民经济建设中的基础性…

跟TED演讲学英文:Teachers need real feedback by Bill Gates

Teachers need real feedback Link: https://www.ted.com/talks/bill_gates_teachers_need_real_feedback Speaker: Bill Gates Date: May 2013 文章目录 Teachers need real feedbackIntroductionVocabularyTranscriptSummary后记 Introduction Until recently, many teach…

电子版图书制作,一键转换可仿真翻页的画册

在数字化浪潮的冲击下&#xff0c;传统纸质图书逐渐被电子版图书取而代之。电子版图书以其便携、环保、更新快速等特点&#xff0c;吸引了越来越多的读者。制作一款既具备电子图书的便捷性&#xff0c;又能仿真翻页的画册&#xff0c;成为当下图书出版行业的新趋势 1.要制作电子…
最新文章