Windows下YUICompress实现js、css混淆压缩

首先,我们针对Linux下的部分命令进行Windows系统的对应实现

ls————cmd /c dir/b
rm————cmd /c del
mv————cmd /c move
pwd————cmd /c chdir
注:cmd /c是执行完命令后关闭命令行窗口、cmd /k是执行完命令后不关闭命令行窗口、cmd /c start是会打开新窗口,关闭旧窗口、cmd /c start是会打开新窗口,不关闭旧窗口

也可以将上述命令做成bat文件,放到Windows/System32目录下,例如,如下文件命名为ls.bat,放到对应目录下,cmd执行ls命令

@echo off
dir

在这里插入图片描述
接下来,全局安装JAVASCRIPT_OBFUSCATOR,需要提前准备好Node环境
在这里插入图片描述

#安装
npm install javascript-obfuscator -g
#检查是否安装成功
javascript-obfuscator -v

然后在系统环境变量指定path,我这里是npm安装,因此,找到npm路径,在系统用户变量的path里,例如C:\Users\zy_ys\AppData\Roaming\npm
在这里插入图片描述
加到系统变量的path里
在这里插入图片描述
还需要准备YUI压缩使用的jar包,这里使用2.4.8版本,下载地址,提取码qc1j,接下来,对应本地项目,改造如下代码,具体改造内容为项目路径、jar包路径、压缩文件路径等,完整代码如下

import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Attribute;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;/*** 通过压缩JS文件、更改日期工具类* 需要系统 MacOS* 需要安装的软件* yui compressor:安装方式 下载jar包 使用时指定包所在路径使用命令即可* uglifyJs: npm 或者 brew 安装* javascript-obfuscator npm安装** @author zwf* @date 20190703*/
public class CompressCommand {private static final String encoding = "utf-8";private static final String[] SUFFIXARRAY = {".js", ".css"};private static final String[] JS_SUFFIXARRAY = {".js"};private static final String TEMP = ".temp";/*** YUI_PATH 压缩使用的jar包路径*/private static final String YUI_PATH = "C:\\Users\\zy_ys\\Desktop\\yuicompressor-2.4.8.jar";/*** JAVASCRIPT_OBFUSCATOR 命令所在路径*/private static final String JAVASCRIPT_OBFUSCATOR_CMD = "javascript-obfuscator";/*** 项目根路径开始的js路径*/private static final String RESOURCES_PATH = "project\\src\\main\\resources\\static\\";/*** 项目根路径开始的HTML路径*/private static final String RESOURCES_HTML_PATH = "project\\src\\main\\resources\\templates\\";/*** JS的文件夹名称*/private static final String[] CSS_JS_DIRECTION = {"js\\aaa", "js\\bbb", "js\\ccc","js\\login","js\\ddd", "js\\eee", "js\\fff", "js\\ggg", "css"};/*** HTML的文件夹名称*/private static final String[] DIRECTION_HTML = {"aaa", "download", "error", "ccc", "ddd", "bbb", "eee", "fff"};/****/private static final String DATE_STAMP = System.currentTimeMillis() + "";/*** 所有未压缩JS的集合*/private static List<String> RESOURCE_LIST = new ArrayList<>();/*** 所有的中间文件HTML*/private static List<String> TEMP_HTML_LIST = new ArrayList<>();/*** 项目跟路径*/private static String PROJECT_PATH = "";private static String CSS_COMPRESS_ONLY = "NO";static {Runtime runtime = Runtime.getRuntime();BufferedReader bufferedReader = null;try {Process process = runtime.exec("cmd /c chdir");if (process.waitFor() == 0) {bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));PROJECT_PATH = bufferedReader.readLine();System.out.println(PROJECT_PATH);}if (StringUtils.isBlank(PROJECT_PATH)) {System.err.println("获取当前项目路径操作失败, 停止操作!");System.exit(-1);}} catch (Exception ex) {ex.printStackTrace();} finally {if (null != bufferedReader) {try {bufferedReader.close();} catch (IOException e) {e.printStackTrace();}}}}enum STEP {/*** 第一步:删除 min.js 文件*/STEP_ONE_RM_OLD_MIN_JS,/*** 第二步:生成新的 min.js 文件*/STEP_TWO_CREATE_NEW_MIN_JS,/*** 第三步: 生成htm中间文件*/STEP_THREE_CREATE_COPY_TEMPLATE,/*** 第四步: 替换中间文件的min.js*/STEP_FOUR_REPLACE_MIN_JS,/*** 第五步: 还原html文件*/STEP_FIVE_DELETE_TEMPLATE,}enum CompressObfuscator {YUI_COMPRESSOR,UGLIFY_JS,JAVASCRIPT_OBFUSCATOR}enum EVN {DEBUG,PUBLISH,}public static void main(String[] args) throws Exception {EVN evn = EVN.DEBUG;//DEBUG是初始化,PUBLISH是混淆压缩System.out.println(" 请输入你需要操作的模式? DEBUG 或者 PUBLISH ");Scanner scanner = new Scanner(System.in);String command = scanner.nextLine();if ("debug".equalsIgnoreCase(command)) {evn = EVN.DEBUG;} else if ("publish".equalsIgnoreCase(command)) {evn = EVN.PUBLISH;} else {System.exit(0);}switch (evn) {case DEBUG:// 还原html文件中的js文件devOps();break;case PUBLISH:masterOps();break;}}enum DevStep {RM_MIN_JS,RP_TEMPLATE_COPY,RM_TEMPLATE,}private static void devOps() throws Exception {// 第一步: 删除min.jsList<String> commandList = initRmJsCommandList();execDevCommand(commandList, DevStep.RM_MIN_JS);// 第二步: 生成中间文件List<String> commandList1 = initTempLateCommandList();execDevCommand(commandList1, DevStep.RP_TEMPLATE_COPY);// 第三步: 替换jsreverseReplaceJsInHtml();// 第四步: 删除html中间文件List<String> backCommand = initDelTemplateList();execDevCommand(backCommand, DevStep.RM_TEMPLATE);}private static void execDevCommand(List<String> commandList, DevStep devStep) {switch (devStep) {case RM_MIN_JS:System.out.println("开始删除min.js文件-----");execute(commandList);System.out.println("结束删除min.js文件-----");break;case RP_TEMPLATE_COPY:System.out.println("开始生成HTML中间文件-----");execute(commandList);System.out.println("结束生成HTML中间文件-----");case RM_TEMPLATE:System.out.println("开始删除html中间文件");execute(commandList);System.out.println("结束删除html中间文件");break;}}private static void masterOps() throws Exception {// step 1 :初始化min.js删除命令集合List<String> rmCmdList = initRmJsCommandList();execCommand(rmCmdList, STEP.STEP_ONE_RM_OLD_MIN_JS);//step 2: 压缩文件,生成新的min.js文件, 如使用yui压缩, 注释掉第一行compressJSCommandListList<String> compressJSCommandList = getCompressCommandList(CompressObfuscator.JAVASCRIPT_OBFUSCATOR);List<String> compressCssCommandList = getCompressCommandList(CompressObfuscator.YUI_COMPRESSOR);execCommand(compressJSCommandList, STEP.STEP_TWO_CREATE_NEW_MIN_JS);execCommand(compressCssCommandList, STEP.STEP_TWO_CREATE_NEW_MIN_JS);//step 3: 生成html中间文件List<String> tempTempLateCommandList = initTempLateCommandList();execCommand(tempTempLateCommandList, STEP.STEP_THREE_CREATE_COPY_TEMPLATE);//step 4: 替换中间文件的min.jsreplaceJsInHtml();//step 5: 恢复HTML文件List<String> backCommand = initDelTemplateList();execCommand(backCommand, STEP.STEP_FIVE_DELETE_TEMPLATE);}private static List<String> getCompressCommandList(CompressObfuscator javascriptObfuscator) throws Exception {switch (javascriptObfuscator) {case YUI_COMPRESSOR:return initCommandList(YUI_PATH);case UGLIFY_JS:CSS_COMPRESS_ONLY = "YES";return initUglifyJsCommandList();case JAVASCRIPT_OBFUSCATOR:CSS_COMPRESS_ONLY = "YES";return initJavascriptObfuscatorCommandList();default:throw new RuntimeException("出错了,停止吧!");}}private static void execCommand(List<String> commandList, STEP step) throws Exception {switch (step) {case STEP_ONE_RM_OLD_MIN_JS:System.out.println("开始清理旧的min.js文件---");execute(commandList);System.out.println("清理旧的min.js文件结束");break;case STEP_TWO_CREATE_NEW_MIN_JS:System.out.println("开始生成新的min.js文件--");execute(commandList);System.out.println("结束生成新的min.js文件--");break;case STEP_THREE_CREATE_COPY_TEMPLATE:System.out.println("开始生成新的html中间文件--");execute(commandList);System.out.println("结束生成新的html中间文件--");break;case STEP_FIVE_DELETE_TEMPLATE:System.out.println("开始还原html文件--");execute(commandList);System.out.println("结束还原html文件--");break;default:}}private static List<String> initUglifyJsCommandList() throws Exception {List<String> cmdList = new ArrayList<>();for (String directionJ : CSS_JS_DIRECTION) {String lsCmd = "ls " + PROJECT_PATH + "/" + RESOURCES_PATH + directionJ;Process process = Runtime.getRuntime().exec(lsCmd);InputStream inputStream = null;BufferedReader bufferedReader = null;if (process.waitFor() == 0) {inputStream = process.getInputStream();bufferedReader = new BufferedReader(new InputStreamReader(inputStream));String line = null;while ((line = bufferedReader.readLine()) != null) {String suffix = line.substring(line.lastIndexOf("."));List<String> suffixList = Arrays.asList(JS_SUFFIXARRAY);if (suffixList.contains(suffix) && !line.endsWith("-min" + suffix)) {StringBuffer _path = new StringBuffer();_path.append(PROJECT_PATH).append("/");_path.append(RESOURCES_PATH).append(directionJ).append("/").append(line).append(" ");RESOURCE_LIST.add(_path.toString());StringBuffer sb = new StringBuffer();sb.append("uglifyjs ");sb.append(_path.toString()).append(" ");sb.append("-c ");sb.append("--ie8 ");sb.append("-m ");sb.append("-o").append(" ");sb.append(PROJECT_PATH).append("/");sb.append(RESOURCES_PATH).append(directionJ).append("/").append(line.replace(suffix, "-" + DATE_STAMP + "-min" + suffix));cmdList.add(sb.toString());}}}}System.out.println("初始化压缩命令成功");return cmdList;}private static List<String> initJavascriptObfuscatorCommandList() throws Exception {List<String> cmdList = new ArrayList<>();for (String directionJ : CSS_JS_DIRECTION) {String lsCmd = "cmd /c dir/b " + PROJECT_PATH + "\\" + RESOURCES_PATH + directionJ;Process process = Runtime.getRuntime().exec(lsCmd);InputStream inputStream = null;BufferedReader bufferedReader = null;if (process.waitFor() == 0) {inputStream = process.getInputStream();bufferedReader = new BufferedReader(new InputStreamReader(inputStream));String line = null;while ((line = bufferedReader.readLine()) != null) {String suffix = line.substring(line.lastIndexOf("."));List<String> suffixList = Arrays.asList(JS_SUFFIXARRAY);if (suffixList.contains(suffix) && !line.endsWith("-min" + suffix)) {StringBuffer _path = new StringBuffer();_path.append(PROJECT_PATH).append("\\");_path.append(RESOURCES_PATH).append(directionJ).append("\\").append(line).append(" ");RESOURCE_LIST.add(_path.toString());StringBuffer sb = new StringBuffer();sb.append(" cmd /c ");sb.append(JAVASCRIPT_OBFUSCATOR_CMD).append(" ");sb.append(_path.toString()).append(" ");sb.append("--output").append(" ");sb.append(PROJECT_PATH).append("\\");sb.append(RESOURCES_PATH).append(directionJ).append("\\").append(line.replace(suffix, "-" + DATE_STAMP + "-min" + suffix));cmdList.add(sb.toString());}}}}System.out.println("初始化压缩命令成功");return cmdList;}private static List<String> initDelTemplateList() throws Exception {List<String> cmdList = new ArrayList<>();for (String htmlFilePath : TEMP_HTML_LIST) {StringBuffer sb = new StringBuffer();sb.append("cmd /c del ").append(" ");sb.append(htmlFilePath).append(" ");cmdList.add(sb.toString());}return cmdList;}private static List<String> initTempLateCommandList() throws Exception {List<String> cmdList = new ArrayList<>();for (String directionH : DIRECTION_HTML) {String lsCmd = "cmd /c dir/b " + PROJECT_PATH + "\\" + RESOURCES_HTML_PATH + directionH;Runtime runtime = Runtime.getRuntime();Process process = runtime.exec(lsCmd);if (process.waitFor() == 0) {InputStream inputStream = null;BufferedReader bufferedReader = null;try {inputStream = process.getInputStream();bufferedReader = new BufferedReader(new InputStreamReader(inputStream));String line = null;while ((line = bufferedReader.readLine()) != null) {if (line.endsWith(".html")) {StringBuilder stringBuilder = new StringBuilder();stringBuilder.append("cmd /c move").append(" ");stringBuilder.append(PROJECT_PATH).append("\\");stringBuilder.append(RESOURCES_HTML_PATH).append(directionH).append("\\").append(line).append(" ");StringBuffer stringBuffer = new StringBuffer();stringBuffer.append(PROJECT_PATH).append("\\");stringBuffer.append(RESOURCES_HTML_PATH).append(directionH).append("\\").append(line).append(TEMP).append(" ");TEMP_HTML_LIST.add(stringBuffer.toString());cmdList.add(stringBuilder.append(stringBuffer.toString()).toString());}}} catch (Exception ex) {ex.printStackTrace();} finally {if (inputStream != null) {inputStream.close();}if (bufferedReader != null) {bufferedReader.close();}}}}return cmdList;}private static synchronized void execute(List<String> commandList) {long beginTime = System.currentTimeMillis();int count = 0;//这里实际定义的是环境变量的地址,我们配置了path,可以忽略String[] envp = new String[] {"PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"};for (String command : commandList) {try {Runtime runtime = Runtime.getRuntime();// Process process = runtime.exec(command, envp);Process process = runtime.exec(command);System.out.println(command);// 如js无法进行压缩打印命令报错信息BufferedInputStream bis = new BufferedInputStream(process.getErrorStream());BufferedReader br = new BufferedReader(new InputStreamReader(bis,"GB2312"));String line;while ((line = br.readLine()) != null) {System.out.println(line);}bis.close();br.close();if (process.waitFor() == 0) {count++;}} catch (Exception ex) {ex.printStackTrace();}}long endTime = System.currentTimeMillis();System.out.println("操作执行完成:共花费 " + (endTime - beginTime) + " ms, 共执行了 " + count + " 个文件");}private static List<String> initRmJsCommandList() throws Exception {List<String> cmdList = new ArrayList<>();for (String directionJ : CSS_JS_DIRECTION) {String lsCmd = "cmd /c dir/b " + PROJECT_PATH + "\\" +  RESOURCES_PATH + directionJ;Runtime runtime = Runtime.getRuntime();Process process = runtime.exec(lsCmd);if (process.waitFor() == 0) {InputStream inputStream = null;BufferedReader bufferedReader = null;try {inputStream = process.getInputStream();bufferedReader = new BufferedReader(new InputStreamReader(inputStream));String line = null;while ((line = bufferedReader.readLine()) != null) {if (line.endsWith("-min.js") || line.endsWith("-min.css")) {StringBuilder stringBuilder = new StringBuilder();stringBuilder.append("cmd /c del").append(" ").append(" ").append(PROJECT_PATH).append("\\").append(RESOURCES_PATH).append(directionJ).append("\\").append(line);System.out.println("cmd:-->"+stringBuilder.toString());cmdList.add(stringBuilder.toString());}}} catch (Exception ex) {ex.printStackTrace();} finally {if (inputStream != null) {inputStream.close();}if (bufferedReader != null) {bufferedReader.close();}}}}return cmdList;}private static void replaceJsInHtml() throws Exception {for (String directionHtml : DIRECTION_HTML) {String absoluteDir = PROJECT_PATH + "\\" + RESOURCES_HTML_PATH + directionHtml;System.out.println("absoluteDir:--->"+absoluteDir);File htmlFile = new File(absoluteDir);File[] htmlFiles = htmlFile.listFiles();for (File hFile : htmlFiles) {BufferedReader bufferedReader = null;BufferedWriter bufferedWriter = null;try {String newFilePath = hFile.getAbsolutePath().substring(0, hFile.getAbsolutePath().indexOf(TEMP));bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(hFile)));bufferedWriter = new BufferedWriter((new OutputStreamWriter(new FileOutputStream(new File(newFilePath)))));String line = null;while ((line = bufferedReader.readLine()) != null) {if (line.trim().contains("script") && line.trim().contains("src")) {Attribute srcAttribute = null;Document document = Jsoup.parse(line.trim());Iterator<Element> iterator = document.select("script").iterator();while (iterator.hasNext()) {Element next = iterator.next();Attributes attributes = next.attributes();for (Attribute attribute : attributes) {if ("src".equals(attribute.getKey())) {srcAttribute = attribute;break;}}break;}boolean w = false;if (srcAttribute != null) {for (String absolutePathName : RESOURCE_LIST) {if (!absolutePathName.trim().endsWith(".js")) {continue;}// 获取js路径上的上一级和js名称String[] split = absolutePathName.split("\\\\");String jsDirName = split[split.length - 2];String jsName = split[split.length - 1];String jsPreName = jsName.substring(0, jsName.indexOf(".js"));String[] srcSpilt = srcAttribute.getValue().split("\\/");String srcJsName = srcSpilt[srcSpilt.length - 1];String srcJsDirName = srcSpilt[srcSpilt.length - 2];if (!absolutePathName.contains("min.js") && jsDirName.equals(srcJsDirName) && srcJsName.contains(jsPreName)) {String newSrc = srcAttribute.getValue().substring(0, srcAttribute.getValue().indexOf(srcJsDirName + "/" + srcJsName));int startIndex = line.indexOf(jsDirName + "/" + jsPreName);int endIndex = line.indexOf(".js\"");String oldJsName = line.substring(startIndex, endIndex);String newLine = line.replace(oldJsName, jsDirName + "/" + jsPreName + "-" + DATE_STAMP + "-min");// 包含当前js文件,替换bufferedWriter.write(newLine + "\n");w = true;}}}if (!w) {bufferedWriter.write(line + "\n");}} else if (line.trim().contains("link") && line.trim().contains("href") && line.trim().contains("css")) {Attribute srcAttribute = null;Document document = Jsoup.parse(line.trim());Iterator<Element> iterator = document.select("link").iterator();while (iterator.hasNext()) {Element next = iterator.next();Attributes attributes = next.attributes();for (Attribute attribute : attributes) {if ("href".equals(attribute.getKey())) {srcAttribute = attribute;break;}}break;}boolean w = false;if (srcAttribute != null) {for (String absolutePathName : RESOURCE_LIST) {if (!absolutePathName.trim().endsWith(".css")) {continue;}// 获取css路径上的上一级和css名称String[] split = absolutePathName.split("\\\\");String cssDirName = split[split.length - 2];String cssName = split[split.length - 1];//System.out.println(cssName);String cssPreName = cssName.substring(0, cssName.indexOf(".css"));String[] srcSpilt = srcAttribute.getValue().split("\\/");String srcJsName = srcSpilt[srcSpilt.length - 1];String srcJsDirName = srcSpilt[srcSpilt.length - 2];if (!absolutePathName.contains("min.css") && cssDirName.equals(srcJsDirName) && srcJsName.contains(cssPreName)) {int startIndex = line.indexOf(cssDirName + "/" + cssPreName);int endIndex = line.indexOf(".css\"");String oldJsName = line.substring(startIndex, endIndex);String newLine = line.replace(oldJsName, cssDirName + "/" + cssPreName + "-" + DATE_STAMP + "-min");// 包含当前css文件,替换bufferedWriter.write(newLine + "\n");w = true;}}}if (!w) {bufferedWriter.write(line + "\n");}} else {bufferedWriter.write(line + "\n");}bufferedWriter.flush();}} catch (Exception ex) {ex.printStackTrace();} finally {if (null != bufferedReader) {bufferedReader.close();}if (null != bufferedWriter) {bufferedWriter.close();}}}}}private static void reverseReplaceJsInHtml() throws Exception {for (String directionHtml : DIRECTION_HTML) {String absoluteDir = PROJECT_PATH + "\\" + RESOURCES_HTML_PATH + directionHtml;File htmlFile = new File(absoluteDir);File[] htmlFiles = htmlFile.listFiles();for (File hFile : htmlFiles) {BufferedReader bufferedReader = null;BufferedWriter bufferedWriter = null;try {String newFilePath = hFile.getAbsolutePath().substring(0, hFile.getAbsolutePath().indexOf(TEMP));bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(hFile)));bufferedWriter = new BufferedWriter((new OutputStreamWriter(new FileOutputStream(new File(newFilePath)))));String line = null;while ((line = bufferedReader.readLine()) != null) {String regex = "-[0-9]{13}-min";Pattern pattern = Pattern.compile(regex);Matcher matcher = pattern.matcher(line.trim());String datestamp_min_js = null;while (matcher.find()) {datestamp_min_js = matcher.group();}if(StringUtils.isNotBlank(datestamp_min_js)){String newLine = line.replace(datestamp_min_js, "");bufferedWriter.write(newLine + "\n");}else {bufferedWriter.write(line + "\n");}bufferedWriter.flush();}} catch (Exception ex) {ex.printStackTrace();} finally {if (null != bufferedReader) {bufferedReader.close();}if (null != bufferedWriter) {bufferedWriter.close();}}}}}/*** 初始化压缩命令** @param yuiPath*/private static List<String> initCommandList(String yuiPath) throws Exception {List<String> cmdList = new ArrayList<>();String[] cssOnly = {".css"};String[] thisSuffixArray = SUFFIXARRAY;if ("YES".equals(CSS_COMPRESS_ONLY)) {thisSuffixArray = cssOnly;}for (String directionJ : CSS_JS_DIRECTION) {String lsCmd = "cmd /c dir/b " + PROJECT_PATH + "\\" + RESOURCES_PATH + directionJ;Process process = Runtime.getRuntime().exec(lsCmd);InputStream inputStream = null;BufferedReader bufferedReader = null;if (process.waitFor() == 0) {inputStream = process.getInputStream();bufferedReader = new BufferedReader(new InputStreamReader(inputStream));String line = null;while ((line = bufferedReader.readLine()) != null) {String suffix = line.substring(line.lastIndexOf("."));List<String> suffixList = Arrays.asList(thisSuffixArray);if (suffixList.contains(suffix) && !line.endsWith("-min" + suffix)) {StringBuffer sb = new StringBuffer();sb.append(" cmd /c");sb.append(" ");sb.append("java -jar ");sb.append(yuiPath);sb.append(" --type ");sb.append(suffix.substring(suffix.indexOf(".") + 1));sb.append(" --charset ");sb.append(encoding).append(" ");sb.append(" --preserve-semi ");StringBuffer _path = new StringBuffer();_path.append(PROJECT_PATH).append("\\");_path.append(RESOURCES_PATH).append(directionJ).append("\\").append(line).append(" ");RESOURCE_LIST.add(_path.toString());sb.append(_path);sb.append(">").append(" ");sb.append(PROJECT_PATH).append("\\");sb.append(RESOURCES_PATH).append(directionJ).append("\\").append(line.replace(suffix, "-" + DATE_STAMP + "-min" + suffix));cmdList.add(sb.toString());}}}}System.out.println("初始化压缩命令成功");return cmdList;}
}

如果遇到问题,可以debug看下是否配置了正确的执行路径、项目路径等,如果要压缩混淆的文件很少,也可以配置好上述内容后,执行如下命令

javascript-obfuscator D:\project\src\main\resources\static\js\login\login.js  --output D:\project\src\main\resources\static\js\login\login-1689667293081-min.js

这里login.js是我们要压缩混淆的文件,login-1689667293081-min.js是压缩混淆后的代码,挂上具体时间戳,然后,将其名称覆盖到对应的html页面即可

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

归并排序与计数排序

目录 一、归并排序 1.基本思想 2.归并排序的特性总结&#xff1a; 3.代码实现&#xff1a; 4.代码优化 &#xff1a; 二、计数排序&#xff08;非比较排序&#xff09; 1. 概念&#xff1a; 2.计数排序的特性总结&#xff1a; 3.代码实现&#xff1a; 一、归并排序 1.…

香农极限是如何影响光纤容量的

1 引言 上世纪末&#xff0c;DWDM技术开始在干线通信中使用并迅速普及。虽然当时DWDM系统的容量只有402.5G&#xff0c;但实验室中DWDM支持的波道数甚至超过了1000波&#xff0c;单波道速率也飙到了惊人的160G&#xff08;超1000波和单波160G是两个独立事件&#xff09;。人们普…

自定义类型:结构体进阶学习分享

自定义类型&#xff1a;结构体进阶学习分享 前言1 结构体的基础知识2 结构的声明3 特殊声明4 结构的自引用5 结构体变量的定义和初始化6 结构体内存对齐6.1 计算结构体大小相关笔试题&#xff08;基于VS&#xff09;笔试题一&#xff1a;笔试题二&#xff1a; 6.2 为什么存在内…

FFmpeg 命令行实现居中高清上下模糊播放效果

FFmpeg 命令行实现居中高清上下模糊播放效果。 1、16:9 的横屏原视频&#xff0c;以 16:9 竖屏上下模糊播放 以该效果播放视频的命令如下&#xff1a; ffplay -i horizontal_test_video_169.mp4 -vf \ "split[a][b]; \ [a]crop(ih/16*9):ih,scaleiw/10:-1,gblursigma5…

深度理解 Spring AOP

一、什么是AOP(面向切面编程)&#xff1f;&#x1f349; AOP 为 Aspect Oriented Programming 的缩写&#xff0c;意思为面向切面编程&#xff0c;是通过预编译方式 和运行期 动态代理 实现程序功能的统一维护的一种技术。 AOP &#xff08;面向切面编程&#xff09;是 OOP&a…

代码随想录额外题目| 数组02 ●189旋转数组 ●724寻找数组中心索引

#189旋转数组 很快写出来但是用了个新数组&#xff0c;不好 void rotate(vector<int>& nums, int k) {vector<int> res(nums.size(),0);for(int i0;i<nums.size();i){int newiik;if(newi>nums.size()-1) newinewi%nums.size();res[newi]nums[i];}numsr…

vue组件(个人学习笔记三)

目录 友情提醒第一章、vue的组件1.1&#xff09;什么是SPA应用1.2&#xff09;vue的组件简介1.3&#xff09;vue工程中的main.js文件 第二章、Vue组件的使用2.1&#xff09;一般组件的自定义2.2&#xff09;注册组件&#xff1a;全局注册和局部注册2.2.1&#xff09;全局注册&a…

和chatgpt学架构04-路由开发

目录 1 什么是路由2 如何设置路由2.1 安装依赖2.2 创建路由文件2.3 创建首页2.4 编写HomePage2.5 更新路由配置2.6 让路由生效 3 测试总结 要想使用vue实现页面的灵活跳转&#xff0c;其中路由配置是必不可少的&#xff0c;我们在做开发的时候&#xff0c;先需要了解知识点&…

Vue--》打造个性化医疗服务的医院预约系统(二)

今天开始使用 vue3 + ts 搭建一个医院预约系统的前台页面,因为文章会将项目的每一个地方代码的书写都会讲解到,所以本项目会分成好几篇文章进行讲解,我会在最后一篇文章中会将项目代码开源到我的GithHub上,大家可以自行去进行下载运行,希望本文章对有帮助的朋友们能多多关…

基于Python+多层RNN+Tensorflow藏头诗与歌词智能生成-深度学习算法应用(含全部工程源码)+训练数据集

目录 前言总体设计系统整体结构图系统流程图 运行环境Python 环境Tensorflow 环境PyCharm环境 模块实现古诗生成1. 数据预处理2. 模型构建3. 模型训练及保存4. 使用模型生成古诗5. 产生藏头诗6. 用词云展示生成的古诗 歌词生成1. 数据预处理2. 模型构建3. 模型训练并保存4. 生成…

基于Kitti数据集的智能驾驶目标检测系统(PyTorch+Pyside6+YOLOv5模型)

摘要&#xff1a;基于Kitti数据集的智能驾驶目标检测系统可用于日常生活中检测与定位行人&#xff08;Pedestrian&#xff09;、面包车&#xff08;Van&#xff09;、坐着的人&#xff08;Person Sitting&#xff09;、汽车&#xff08;Car&#xff09;、卡车&#xff08;Truck…

【字符流】案例:文件到集合

案例&#xff1a;文件到集合 1.需求&#xff1a; 把文本文件中的数据读取到集合&#xff0c;并遍历集合。要求&#xff1a;文件中的每一行数据是一个集合元素 2.思路 创建字符缓冲输入流对象创建ArrayList集合对象调用字符缓冲输入流对象的方法读数据把读取到的字符串数据存…

Java IO

stream 流 是一种抽象概念&#xff0c;它代表了数据的无结构化传递。按照流的方式进行输入输出&#xff0c;数据被当成 无结构的字节序或字符序列。从流中取得数据的操作称为提取操作&#xff0c;而向流中添加数据的操作称为插入操作。用来进行输入输出操作的流就称为IO 流。换…

spring复习:(50)@Configuration注解配置的singleton的bean是什么时候被创建出来并缓存到容器的?

一、主类&#xff1a; 二、配置类&#xff1a; 三、singleton bean的创建流程 运行到context.refresh(); 进入refresh方法&#xff1a; 向下运行到红线位置时&#xff1a; 会实例化所有的singleton bean.进入finisheBeanFactoryInitialization方法&#xff1a; 向下拖动代…

JavaWeb课程设计项目实战(06)——项目编码实践3

版权声明 本文原创作者&#xff1a;谷哥的小弟作者博客地址&#xff1a;http://blog.csdn.net/lfdfhl 在本教程教程中&#xff0c;我们实现学生列表的显示。 Student 请在bean包下创建Student类&#xff0c;代码如下&#xff1a; package com.cn.bean; /*** 本文作者&#…

数据科学团队的角色分工

描述数据科学团队中角色分工常用下列维度。进一步以数据可视化直观表达的能力雷达图: ML Ops - 机器学习运维 Data Pipelines - 数据流水线 Database - 数据库 Data Viz - 数据可视化 Storytelling - 数据讲故事 Business Insights - 业务洞察 Reporting - 报告 Experimentatio…

【100天精通python】Day10:函数的创建和调用,参数传递,返回值,变量作用域以及匿名函数

目录 1. 函数的创建和调用 1.1 函数的创建 1.2 调用函数 2 参数传递 2.1 传递方式 2.2 形参和实参 2.3 位置参数 2.4 关键字参数 2.5 可变参数 2.6 为参数设置默认值 3 返回值 4 变量的作用域 4.1 局部变量 4.2 嵌套变量 4.3 全局变量 5 匿名函数&#xff0…

X86设备启动过程

文章目录 一、电源自检二、BIOS自检三、引导设备选择四、主引导记录4.1 0x7c0 五、加载操作系统 x86计算机启动过程&#xff0c;主要分为这几个阶段&#xff1a;电源自检、BIOS自检、引导设备的选择、主引导记录、加载操作系统。 一、电源自检 当我们按下开关键后&#xff0c;…

uni-app image加载错误 404 替换为默认图片

双层v-for 使用item修改 aitem.cat_icon || defaultPic绑定图片src属性为aitem.cat_icon 如果aitem.cat_icon的值为空字符串或undefined&#xff0c;那么默认图片defaultPic被显示出来当图片加载错误时,触发handleImageError方法,将aitem传进去 <!-- 页面--><view …

Java 知识合集 | 多线程与并发

&#x1f468;&#x1f3fb;‍&#x1f4bb; 热爱摄影的程序员 &#x1f468;&#x1f3fb;‍&#x1f3a8; 喜欢编码的设计师 &#x1f9d5;&#x1f3fb; 擅长设计的剪辑师 &#x1f9d1;&#x1f3fb;‍&#x1f3eb; 一位高冷无情的编码爱好者 大家好&#xff0c;我是 DevO…