【node.js】入门基础

在这里插入图片描述

个人主页:Guiat
归属专栏:node.js

在这里插入图片描述

文章目录

  • 1. Node.js简介
    • 1.1 Node.js的核心特点
    • 1.2 Node.js适用场景
  • 2. 第一个Node.js程序
    • 2.1 创建并运行Hello World
    • 2.2 创建简单的HTTP服务器
  • 3. Node.js核心概念
    • 3.1 模块系统
      • 3.1.1 创建和导出模块
      • 3.1.2 导入和使用模块
      • 3.1.3 ES模块语法(ES Modules)
    • 3.2 事件循环
      • 3.2.1 事件循环示例
      • 3.2.2 异步文件操作示例
    • 3.3 事件发射器 (EventEmitter)
      • 3.3.1 自定义事件发射器
    • 3.4 流 (Streams)
      • 3.4.1 流的类型
      • 3.4.2 文件流示例
      • 3.4.3 使用pipe()简化流操作
      • 3.4.4 创建自定义流
  • 4. 文件系统操作
    • 4.1 同步与异步文件操作
    • 4.2 写入文件
    • 4.3 目录操作
    • 4.4 文件路径操作
  • 5. HTTP服务器开发
    • 5.1 创建基本HTTP服务器
    • 5.2 处理HTTP请求和路由
    • 5.3 处理静态文件

正文

1. Node.js简介

Node.js是一个开源、跨平台的JavaScript运行环境,它允许开发者使用JavaScript来编写服务器端代码。Node.js采用Google Chrome的V8引擎来执行JavaScript代码,具有非阻塞I/O和事件驱动机制,使其成为构建高性能网络应用的理想选择。

1.1 Node.js的核心特点

Node.js核心特点
非阻塞I/O
事件驱动
单线程
跨平台
npm生态系统
  • 非阻塞I/O:执行I/O操作时不会阻塞线程
  • 事件驱动:基于事件循环处理并发操作
  • 单线程:使用单线程处理多个并发连接
  • 跨平台:可在Windows、macOS和Linux等多种操作系统上运行
  • npm:拥有世界上最大的开源代码库生态系统

1.2 Node.js适用场景

Node.js特别适合以下场景:

  • 实时应用(聊天、游戏服务器)
  • REST API和微服务
  • 单页面应用(SPA)的后端
  • 流处理和数据密集型应用
  • 命令行工具

2. 第一个Node.js程序

2.1 创建并运行Hello World

创建一个名为hello.js的文件,内容如下:

// 第一个Node.js程序
console.log("Hello, Node.js!");

在命令行中运行:

node hello.js

输出结果:

Hello, Node.js!

2.2 创建简单的HTTP服务器

创建一个基本的Web服务器:

// 创建简单的HTTP服务器
const http = require('http');// 创建HTTP服务器
const server = http.createServer((req, res) => {// 设置响应头res.writeHead(200, {'Content-Type': 'text/plain'});// 发送响应数据res.end('Hello World from Node.js Server!');
});// 服务器监听3000端口
const PORT = 3000;
server.listen(PORT, () => {console.log(`Server running at http://localhost:${PORT}/`);
});

运行服务器:

node server.js

现在可以在浏览器中访问http://localhost:3000查看结果。

3. Node.js核心概念

3.1 模块系统

Node.js使用CommonJS模块系统,允许将代码分割成可重用的部分。

3.1.1 创建和导出模块

// math.js - 创建一个数学工具模块
function add(a, b) {return a + b;
}function subtract(a, b) {return a - b;
}function multiply(a, b) {return a * b;
}function divide(a, b) {if (b === 0) {throw new Error('Cannot divide by zero');}return a / b;
}// 导出多个函数
module.exports = {add,subtract,multiply,divide
};

3.1.2 导入和使用模块

// app.js - 使用数学工具模块
const math = require('./math');console.log(`2 + 3 = ${math.add(2, 3)}`);
console.log(`5 - 2 = ${math.subtract(5, 2)}`);
console.log(`4 * 6 = ${math.multiply(4, 6)}`);
console.log(`10 / 2 = ${math.divide(10, 2)}`);// 也可以使用解构赋值
const { add, multiply } = require('./math');
console.log(`4 + 5 = ${add(4, 5)}`);
console.log(`3 * 7 = ${multiply(3, 7)}`);

3.1.3 ES模块语法(ES Modules)

Node.js也支持ES模块语法,需要将文件后缀改为.mjs或在package.json中设置"type": "module"

// mathES.mjs - ES模块语法
export function add(a, b) {return a + b;
}export function subtract(a, b) {return a - b;
}// 导出默认值
export default {name: 'Math Utils',version: '1.0.0'
};
// appES.mjs - 导入ES模块
import { add, subtract } from './mathES.mjs';
import mathInfo from './mathES.mjs';console.log(`ES模块: 2 + 3 = ${add(2, 3)}`);
console.log(`模块信息: ${mathInfo.name} v${mathInfo.version}`);

3.2 事件循环

Node.js的事件循环是其非阻塞I/O模型的核心,它允许Node.js执行非阻塞操作。

事件循环
定时器阶段
待定回调阶段
idle/prepare阶段
轮询阶段
检查阶段
关闭回调阶段

3.2.1 事件循环示例

console.log('1. 开始执行');// 延迟执行 (宏任务)
setTimeout(() => {console.log('4. setTimeout 回调执行');
}, 0);// Promise (微任务)
Promise.resolve().then(() => {console.log('3. Promise 回调执行');
});console.log('2. 结束执行');// 输出顺序:
// 1. 开始执行
// 2. 结束执行
// 3. Promise 回调执行
// 4. setTimeout 回调执行

3.2.2 异步文件操作示例

const fs = require('fs');console.log('1. 开始读取文件');// 异步读取文件
fs.readFile('example.txt', 'utf8', (err, data) => {if (err) {console.error('读取文件出错:', err);return;}console.log('3. 文件内容:', data);
});console.log('2. 读取文件的请求已发出,继续执行其他操作');

3.3 事件发射器 (EventEmitter)

EventEmitter是Node.js的核心模块,用于实现事件驱动架构。

const EventEmitter = require('events');// 创建事件发射器实例
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();// 注册事件监听器
myEmitter.on('event', (a, b) => {console.log('事件发生了!', a, b);
});// 注册只执行一次的事件监听器
myEmitter.once('onceEvent', () => {console.log('这个事件只会触发一次');
});// 触发事件
myEmitter.emit('event', 'a', 'b');
myEmitter.emit('onceEvent');
myEmitter.emit('onceEvent'); // 这次不会触发监听器

3.3.1 自定义事件发射器

const EventEmitter = require('events');// 创建一个用户类,继承EventEmitter
class User extends EventEmitter {constructor(name) {super();this.name = name;}sayHello() {console.log(`${this.name} says hello!`);// 触发事件this.emit('hello', this.name);}sayGoodbye() {console.log(`${this.name} says goodbye!`);// 触发事件this.emit('goodbye', this.name);}
}// 创建用户实例
const user = new User('John');// 添加事件监听器
user.on('hello', (name) => {console.log(`Hello event was triggered by ${name}`);
});user.on('goodbye', (name) => {console.log(`Goodbye event was triggered by ${name}`);
});// 调用方法,触发事件
user.sayHello();
user.sayGoodbye();

3.4 流 (Streams)

流是用于处理读写数据的抽象接口,尤其适合处理大文件。

3.4.1 流的类型

  • 可读流 (Readable):用于读取数据
  • 可写流 (Writable):用于写入数据
  • 双工流 (Duplex):可读可写
  • 转换流 (Transform):在读写过程中修改数据

3.4.2 文件流示例

const fs = require('fs');// 创建可读流
const readStream = fs.createReadStream('source.txt', 'utf8');// 创建可写流
const writeStream = fs.createWriteStream('destination.txt');// 处理流事件
readStream.on('data', (chunk) => {console.log(`接收到 ${chunk.length} 字节的数据`);// 写入数据到可写流writeStream.write(chunk);
});readStream.on('end', () => {writeStream.end(); // 结束写入流console.log('读取完成');
});readStream.on('error', (err) => {console.error('读取错误:', err);
});writeStream.on('finish', () => {console.log('写入完成');
});writeStream.on('error', (err) => {console.error('写入错误:', err);
});

3.4.3 使用pipe()简化流操作

const fs = require('fs');// 创建可读流和可写流
const readStream = fs.createReadStream('source.txt');
const writeStream = fs.createWriteStream('destination.txt');// 使用pipe直接将可读流连接到可写流
readStream.pipe(writeStream);// 处理事件
readStream.on('end', () => {console.log('读取完成');
});writeStream.on('finish', () => {console.log('写入完成');
});

3.4.4 创建自定义流

const { Transform } = require('stream');// 创建转换流,将文本转为大写
class UppercaseTransform extends Transform {_transform(chunk, encoding, callback) {// 转换数据const upperChunk = chunk.toString().toUpperCase();// 推送转换后的数据this.push(upperChunk);// 调用回调,表示处理完成callback();}
}// 使用自定义转换流
const upperCaseStream = new UppercaseTransform();// 从标准输入读取,经过转换后写入标准输出
process.stdin.pipe(upperCaseStream).pipe(process.stdout);

4. 文件系统操作

Node.js提供了fs模块用于与文件系统交互。

4.1 同步与异步文件操作

const fs = require('fs');// 同步读取文件(阻塞)
try {const data = fs.readFileSync('file.txt', 'utf8');console.log('同步读取文件:', data);
} catch (err) {console.error('同步读取错误:', err);
}// 异步读取文件(非阻塞)
fs.readFile('file.txt', 'utf8', (err, data) => {if (err) {console.error('异步读取错误:', err);return;}console.log('异步读取文件:', data);
});// 使用Promise API (Node.js 10+)
fs.promises.readFile('file.txt', 'utf8').then(data => {console.log('Promise读取文件:', data);}).catch(err => {console.error('Promise读取错误:', err);});// 使用async/await (Node.js 10+)
async function readFileAsync() {try {const data = await fs.promises.readFile('file.txt', 'utf8');console.log('Async/Await读取文件:', data);} catch (err) {console.error('Async/Await读取错误:', err);}
}readFileAsync();

4.2 写入文件

const fs = require('fs');// 同步写入
try {fs.writeFileSync('output1.txt', 'Hello, Node.js! (同步写入)', 'utf8');console.log('同步写入完成');
} catch (err) {console.error('同步写入错误:', err);
}// 异步写入
fs.writeFile('output2.txt', 'Hello, Node.js! (异步写入)', 'utf8', (err) => {if (err) {console.error('异步写入错误:', err);return;}console.log('异步写入完成');
});// 追加内容到文件
fs.appendFile('output2.txt', '\n这是追加的内容', 'utf8', (err) => {if (err) {console.error('追加错误:', err);return;}console.log('追加完成');
});

4.3 目录操作

const fs = require('fs');
const path = require('path');// 创建目录
fs.mkdir('new-directory', (err) => {if (err) {console.error('创建目录错误:', err);return;}console.log('目录创建成功');
});// 递归创建多级目录
fs.mkdir('parent/child/grandchild', { recursive: true }, (err) => {if (err) {console.error('创建多级目录错误:', err);return;}console.log('多级目录创建成功');
});// 读取目录内容
fs.readdir('.', (err, files) => {if (err) {console.error('读取目录错误:', err);return;}console.log('当前目录文件:');files.forEach(file => {console.log(`- ${file}`);});
});// 获取文件信息
fs.stat('file.txt', (err, stats) => {if (err) {console.error('获取文件信息错误:', err);return;}console.log('文件信息:');console.log(`- 是文件? ${stats.isFile()}`);console.log(`- 是目录? ${stats.isDirectory()}`);console.log(`- 文件大小: ${stats.size} 字节`);console.log(`- 创建时间: ${stats.birthtime}`);console.log(`- 修改时间: ${stats.mtime}`);
});

4.4 文件路径操作

const path = require('path');// 路径拼接 (跨平台兼容)
const fullPath = path.join(__dirname, 'subfolder', 'file.txt');
console.log('拼接路径:', fullPath);// 解析路径
const pathInfo = path.parse('/home/user/documents/file.txt');
console.log('路径信息:', pathInfo);
/*
输出:
{root: '/',dir: '/home/user/documents',base: 'file.txt',ext: '.txt',name: 'file'
}
*/// 规范化路径
console.log('规范化路径:', path.normalize('/home//user/../user/docs/'));
// 输出: /home/user/docs/// 获取绝对路径
console.log('绝对路径:', path.resolve('subfolder', 'file.txt'));// 获取扩展名
console.log('扩展名:', path.extname('file.txt')); // 输出: .txt

5. HTTP服务器开发

5.1 创建基本HTTP服务器

const http = require('http');// 创建HTTP服务器
const server = http.createServer((req, res) => {// 获取请求信息const { method, url, headers } = req;console.log(`收到 ${method} 请求: ${url}`);// 根据URL路径提供不同响应if (url === '/') {// 设置响应头res.writeHead(200, {'Content-Type': 'text/html'});// 发送响应数据res.end(`<html><head><title>Node.js服务器</title></head><body><h1>欢迎来到Node.js服务器!</h1><p>当前时间: ${new Date().toLocaleString()}</p><ul><li><a href="/about">关于我们</a></li><li><a href="/contact">联系我们</a></li></ul></body></html>`);} else if (url === '/about') {res.writeHead(200, {'Content-Type': 'text/html'});res.end(`<html><head><title>关于我们</title></head><body><h1>关于我们</h1><p>这是一个简单的Node.js HTTP服务器示例。</p><a href="/">返回首页</a></body></html>`);}else if (url === '/contact') {res.writeHead(200, {'Content-Type': 'text/html'});res.end(`<html><head><title>联系我们</title></head><body><h1>联系我们</h1><p>Email: example@example.com</p><a href="/">返回首页</a></body></html>`);}else if (url === '/api/time') {// 返回JSON数据res.writeHead(200, {'Content-Type': 'application/json'});res.end(JSON.stringify({time: new Date().toISOString(),timestamp: Date.now()}));}else {// 404 Not Foundres.writeHead(404, {'Content-Type': 'text/html'});res.end(`<html><head><title>404 Not Found</title></head><body><h1>404 - 页面不存在</h1><p>请求的URL "${url}" 不存在</p><a href="/">返回首页</a></body></html>`);}
});// 服务器监听端口
const PORT = process.env.PORT || 3000;
server.listen(PORT, () => {console.log(`服务器运行在 http://localhost:${PORT}/`);
});

5.2 处理HTTP请求和路由

const http = require('http');
const url = require('url');// 路由处理函数
const routes = {'GET': {'/': (req, res) => {res.writeHead(200, {'Content-Type': 'text/html'});res.end('<h1>首页</h1><p>欢迎访问我们的网站</p>');},'/about': (req, res) => {res.writeHead(200, {'Content-Type': 'text/html'});res.end('<h1>关于我们</h1><p>这是关于页面</p>');},'/api/users': (req, res) => {const users = [{ id: 1, name: 'Alice' },{ id: 2, name: 'Bob' },{ id: 3, name: 'Charlie' }];res.writeHead(200, {'Content-Type': 'application/json'});res.end(JSON.stringify(users));}},'POST': {'/api/users': (req, res) => {let body = '';// 收集请求体数据req.on('data', chunk => {body += chunk.toString();});// 请求体接收完毕req.on('end', () => {try {const userData = JSON.parse(body);// 处理用户数据...res.writeHead(201, {'Content-Type': 'application/json'});res.end(JSON.stringify({message: '用户创建成功',user: userData}));} catch (error) {res.writeHead(400, {'Content-Type': 'application/json'});res.end(JSON.stringify({error: '无效的JSON数据'}));}});}}
};// 创建HTTP服务器
const server = http.createServer((req, res) => {// 解析URL和查询参数const parsedUrl = url.parse(req.url, true);const path = parsedUrl.pathname;const method = req.method.toUpperCase();const query = parsedUrl.query;console.log(`${method} ${path}`);// 查找路由处理函数const routeHandler = routes[method] && routes[method][path];if (routeHandler) {// 将查询参数附加到请求对象req.query = query;// 调用路由处理函数routeHandler(req, res);} else {// 未找到路由处理函数,返回404res.writeHead(404, {'Content-Type': 'text/html'});res.end('<h1>404 - 页面不存在</h1>');}
});// 启动服务器
const PORT = 3000;
server.listen(PORT, () => {console.log(`服务器运行在 http://localhost:${PORT}/`);
});

5.3 处理静态文件

const http = require('http');
const fs = require('fs');
const path = require('path');// 静态文件目录
const PUBLIC_DIR = path.join(__dirname, 'public');// MIME类型映射
const MIME_TYPES = {'.html': 'text/html','.css': 'text/css','.js': 'text/javascript','.json': 'application/json','.png': 'image/png','.jpg': 'image/jpeg','.jpeg': 'image/jpeg','.gif': 'image/gif','.svg': 'image/svg+xml','.ico': 'image/x-icon','.txt': 'text/plain'
};// 创建HTTP服务器
const server = http.createServer((req, res) => {// 仅处理GET请求if (req.method !== 'GET') {res.writeHead(405, {'Content-Type': 'text/plain'});res.end('Method Not Allowed');return;}// 获取请求路径let filePath = path.join(PUBLIC_DIR, req.url === '/' ? 'index.html' : req.url);// 检查文件是否存在fs.stat(filePath, (err, stats) => {if (err) {// 文件不存在,返回404res.writeHead(404, {'Content-Type': 'text/html'});res.end('<h1>404 - 文件未找到</h1>');return;}// 如果是目录,尝试加载index.htmlif (stats.isDirectory()) {filePath = path.join(filePath, 'index.html');}// 获取文件扩展名const extname = path.extname(filePath);// 获取MIME类型const contentType = MIME_TYPES[extname] || 'application/octet-stream';// 读取并发送文件fs.readFile(filePath, (err, content) => {if (err) {if (err.code === 'ENOENT') {// 文件不存在res.writeHead(404, {'Content-Type': 'text/html'});res.end('<h1>404 - 文件未找到</h1>');} else {// 服务器错误res.writeHead(500, {'Content-Type': 'text/html'});res.end('<h1>500 - 服务器错误</h1>');}} else {// 发送文件res.writeHead(200, {'Content-Type': contentType});res.end(content);}});});
});// 启动服务器
const PORT = 3000;
server.listen(PORT, () => {console.log(`静态文件服务器运行在 http://localhost:${PORT}/`);console.log(`提供目录: ${PUBLIC_DIR}`);
});

结语
感谢您的阅读!期待您的一键三连!欢迎指正!

在这里插入图片描述

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

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

相关文章

百度飞桨PaddleOCR 3.0开源发布 OCR精度跃升13%

百度飞桨 PaddleOCR 3.0 开源发布 2025 年 5 月 20 日&#xff0c;百度飞桨团队正式发布了 PaddleOCR 3.0 版本&#xff0c;并将其开源。这一新版本在文字识别精度、多语种支持、手写体识别以及高精度文档解析等方面取得了显著进展&#xff0c;进一步提升了 PaddleOCR 在 OCR …

Android 14 Binderized HAL开发实战指南(AIDL版)

Android 14 Binderized HAL开发实战指南&#xff08;AIDL版&#xff09; 环境要求 Android 14源码编译环境AOSP android-14.0.0_r7分支Soong build系统Java 17 & NDK r25c 项目结构 hardware/interfaces/myservice/ ├── 1.0 │ ├── IMyHalService.aidl # AID…

第九天的尝试

目录 一、每日一言 二、练习题 三、效果展示 四、下次题目 五、总结 一、每日一言 创造美好的代价是努力&#xff0c;失望以及毅力&#xff0c;首先是痛苦&#xff0c;然后才是欢乐。 时间是快的&#xff0c;看怎么利用&#xff0c;安排好一切事情&#xff0c;才能从容面对…

交安安全员:交通工程安全领域的关键角色

在交通工程这个庞大而复杂的领域中&#xff0c;交安安全员扮演着举足轻重的角色&#xff0c;他们是安全的捍卫者&#xff0c;是交通工程顺利推进的重要保障。​ 交安安全员&#xff0c;专门从事公路水运工程施工企业安全生产管理工作。他们的专业身份由交通运输部门颁发的交安…

实验-设计一个应用系统(计算机组成原理)

目录 一. 实验内容 二. 实验步骤 &#xff08;1&#xff09;七段数码管显示模块 &#xff08;2&#xff09;指令模块 &#xff08;3&#xff09;控制模块 &#xff08;4&#xff09;ALU模块 &#xff08;5&#xff09;CPU模块 三. 实现效果 四. 实验环境 五. 实验小结…

【博客系统】博客系统第四弹:令牌技术

令牌机制 为什么不能使用 Session 实现登录功能&#xff1f; 传统思路&#xff1a; 登录页面把用户名密码提交给服务器。服务器端验证用户名密码是否正确&#xff0c;并返回校验结果给前端。如果密码正确&#xff0c;则在服务器端创建 Session。通过 Cookie 把 sessionId 返回…

【瑞数3代】药监评审中心逆向分析 | 后缀MmEwMD参数

1.目标 目标网址&#xff1a;https://www.cde.org.cn/main/news/listpage/545cf855a50574699b46b26bcb165f32 import requestscookies {FSSBBIl1UgzbN7N80S: 8sYeMWaC_IHoNl8Ckfx2y9MLiueMCkPr2V3MIoZkrMPUfzMMaXKzAoxpNPvyw4lt,Path: /,FSSBBIl1UgzbN7N80T: 3js3ygV.St6BvO20…

【漫话机器学习系列】274.基尼指数(Gini Index)

决策树中的基尼指数&#xff08;Gini Index&#xff09;详解 —— 从公式理解到实际应用 在构建决策树模型时&#xff0c;一个核心问题是&#xff1a;如何选择最优的特征来进行节点划分&#xff1f; 这就涉及到了“划分准则”的问题。常见的准则有信息增益、信息增益率以及本文…

R语言学习--Day07--T分布与T检验

昨天我们介绍了R中用于对数据进行分类的聚类分析的方法&#xff0c;接下来我们来看T分布。 T分布 T分布适用于帮我们估计整组数据&#xff08;较小的数据量&#xff0c;一般小于30&#xff09;的真实值在哪一个区间&#xff0c;具体是计算置信区间&#xff08;一般为95%&#…

数据结构与算法-线性表-双向链表(Double Linked List)

1 线性表 1.4 双向链表&#xff08;Double Linked List&#xff09; 双向链表的结点中有两个指针域&#xff0c;一个指向直接后继&#xff0c;另一个指向直接前驱&#xff0c;主要是为了解决前向查找的问题。 双向链表结构&#xff1a; 书籍和视频教程都只讲解了插入和删除的…

甘特图实例 dhtmlxGantt.js

本文介绍了如何使用dhtmlxGantt库创建一个基础的甘特图示例&#xff0c;并对其进行汉化和自定义配置。首先&#xff0c;通过引入dhtmlxgantt.css和dhtmlxgantt.js文件初始化甘特图。接着&#xff0c;通过设置gantt.i18n.setLocale("cn")实现核心文本的汉化&#xff0…

C++23 新增扁平化关联容器详解

文章目录 一、引言已有关联容器回顾新容器的引入原因 二、std::flat_set定义与特性代码示例适用场景 三、std::flat_multiset定义与特性代码示例适用场景 四、std::flat_map定义与特性代码示例适用场景 五、std::flat_multimap定义与特性代码示例适用场景 六、与其他容器的比较…

使用zap,对web应用/API接口 做安全检测

https://www.zaproxy.org/getting-started/ 检测方法 docker pull ghcr.io/zaproxy/zaproxy:stable# 执行baseline测试 docker run -t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py \ -t https://baseline.yeshen.org# 执行api测试 docker run -t ghcr.io/zaproxy/zaproxy…

Qt—模态与非模态对话框

Qt—模态与非模态对话框 核心概念 ​模态对话框​​&#xff1a;强制用户优先处理当前窗口&#xff0c;阻塞指定范围的用户交互。​非模态对话框​​&#xff1a;允许用户自由切换窗口&#xff0c;无交互限制。 一、模态对话框类型与行为 1. 应用级模态&#xff08;Applica…

Axure高保真CRM客户关系管理系统原型

一套出色的CRM&#xff08;客户关系管理&#xff09;系统&#xff0c;无疑是企业管理者掌控客户动态、提升销售业绩的得力助手。今天&#xff0c;就为大家介绍一款精心打造的Axure高保真CRM客户关系管理系统原型模板&#xff0c;助你轻松开启高效客户管理之旅。 这款CRM原型模…

【羊圈——状压 + DP / 记忆化搜索DP】

题目 一般DP代码&#xff08;注意&#xff0c;这里只能向外推(起始状态是f(1,0)&#xff0c;不能向内推&#xff08;不然会导致之前的羊圈被割裂&#xff09;&#xff09; #include <bits/stdc.h> using namespace std;const int MAX_N 210; const int MAX_M 16;int n…

讲解Mysql InnoDB的MVCC

1. 定义 MVCC是多版本并发控制&#xff08;Multi - Version Concurrency Control&#xff09;的缩写。它是InnoDB存储引擎实现高并发控制的一种机制。在数据库系统中&#xff0c;多个事务可能会同时对数据进行读写操作&#xff0c;而MVCC通过为数据行保存多个版本来解决并发事务…

ZeroMQ Sockets介绍及应用示例

1. 概念解释 ZeroMQ Sockets提供了一种类标准套接字&#xff08;socket-like&#xff09;的 API&#xff0c;是消息导向的通信机制&#xff0c;基于 TCP/UDP 等传输层协议&#xff0c;但封装了底层细节&#xff08;如连接管理、消息路由、缓冲区等&#xff09;&#xff0c;提供…

语音合成之十五 语音合成(TTS)分句生成拼接时的响度一致性问题:现状、成因与对策

语音合成&#xff08;TTS&#xff09;分句生成拼接时的响度一致性问题&#xff1a;现状、成因与对策 引言&#xff1a;分段式文本转语音中的响度一致性挑战业界对响度差异问题的认知拼接语音片段中响度变化的根本原因分段拼接的固有挑战各片段预测韵律特征的差异文本特征和模型…

Android中Binder驱动作用?

Binder驱动的作用与核心功能 Binder驱动是Android系统中实现进程间通信&#xff08;IPC&#xff09;的核心底层组件&#xff0c;它工作于Linux内核层&#xff0c;负责管理跨进程通信的建立、数据传输、资源同步等关键任务。以下是其核心作用及实现细节&#xff1a; 1. ​​进程…