WPF 按钮点击音效实现
WPF 按钮点击音效实现
下面我将为您提供一个完整的 WPF 按钮点击音效实现方案,包含多种实现方式和高级功能:
完整实现方案
MainWindow.xaml
<Window x:Class="ButtonClickSound.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:ButtonClickSound"mc:Ignorable="d"Title="按钮点击音效演示" Height="450" Width="800"WindowStartupLocation="CenterScreen"Background="#FF1E1E1E"><Window.Resources><!-- 音效资源 --><MediaPlayer x:Key="ClickSoundPlayer" Source="sounds/click.wav" Volume="0.7"/><MediaPlayer x:Key="HoverSoundPlayer" Source="sounds/hover.wav" Volume="0.5"/><!-- 按钮样式 --><Style x:Key="SoundButtonStyle" TargetType="Button"><Setter Property="Background" Value="#FF252526"/><Setter Property="Foreground" Value="White"/><Setter Property="BorderBrush" Value="#FF3F3F46"/><Setter Property="BorderThickness" Value="1"/><Setter Property="FontSize" Value="18"/><Setter Property="Padding" Value="20,10"/><Setter Property="Margin" Value="10"/><Setter Property="Cursor" Value="Hand"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="Button"><Border x:Name="border" Background="{TemplateBinding Background}"BorderBrush="{TemplateBinding BorderBrush}"BorderThickness="{TemplateBinding BorderThickness}"CornerRadius="8"><ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"Margin="{TemplateBinding Padding}"/></Border><ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter Property="Background" Value="#FF3A80D2"/><Setter Property="BorderBrush" Value="#FF2A70C2"/></Trigger><Trigger Property="IsPressed" Value="True"><Setter Property="Background" Value="#FF2A70C2"/><Setter Property="BorderBrush" Value="#FF1A60B2"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style></Window.Resources><Grid><Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="*"/><RowDefinition Height="Auto"/></Grid.RowDefinitions><!-- 标题 --><TextBlock Text="按钮点击音效演示" Grid.Row="0"FontSize="28"FontWeight="Bold"Foreground="White"HorizontalAlignment="Center"Margin="0,20"/><!-- 按钮区域 --><Grid Grid.Row="1"><Grid.ColumnDefinitions><ColumnDefinition Width="*"/><ColumnDefinition Width="*"/></Grid.ColumnDefinitions><!-- 简单实现 --><StackPanel Grid.Column="0" VerticalAlignment="Center"HorizontalAlignment="Center"><TextBlock Text="简单实现" FontSize="20"Foreground="#AAAAAA"HorizontalAlignment="Center"Margin="0,0,0,20"/><!-- 直接绑定事件 --><Button Content="事件处理器" Style="{StaticResource SoundButtonStyle}"Click="ButtonWithEventHandler_Click"/><!-- 使用行为 --><Button Content="使用行为" Style="{StaticResource SoundButtonStyle}"local:SoundBehavior.ClickSound="{StaticResource ClickSoundPlayer}"/><!-- 使用命令 --><Button Content="使用命令" Style="{StaticResource SoundButtonStyle}"Command="{Binding PlaySoundCommand}"/></StackPanel><!-- 高级实现 --><StackPanel Grid.Column="1" VerticalAlignment="Center"HorizontalAlignment="Center"><TextBlock Text="高级实现" FontSize="20"Foreground="#AAAAAA"HorizontalAlignment="Center"Margin="0,0,0,20"/><!-- 悬停+点击音效 --><Button Content="悬停+点击音效" Style="{StaticResource SoundButtonStyle}"local:SoundBehavior.HoverSound="{StaticResource HoverSoundPlayer}"local:SoundBehavior.ClickSound="{StaticResource ClickSoundPlayer}"/><!-- 自定义音效 --><Button Content="自定义音效" Style="{StaticResource SoundButtonStyle}"local:SoundBehavior.ClickSound="{StaticResource ClickSoundPlayer}"Click="CustomSoundButton_Click"/><!-- 随机音效 --><Button Content="随机音效" Style="{StaticResource SoundButtonStyle}"Click="RandomSoundButton_Click"/></StackPanel></Grid><!-- 控制面板 --><Border Grid.Row="2"Background="#202020"CornerRadius="10"Padding="20"Margin="20"HorizontalAlignment="Center"><StackPanel Orientation="Horizontal" Spacing="20"><Button Content="播放点击音效" Style="{StaticResource SoundButtonStyle}"Click="PlaySound_Click"/><Button Content="停止所有音效" Style="{StaticResource SoundButtonStyle}"Click="StopAllSounds_Click"/><Button Content="切换静音模式" Style="{StaticResource SoundButtonStyle}"Click="ToggleMute_Click"/></StackPanel></Border></Grid>
</Window>
SoundBehavior.cs (音效行为类)
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;namespace ButtonClickSound
{public static class SoundBehavior{#region ClickSound 附加属性public static MediaPlayer GetClickSound(DependencyObject obj){return (MediaPlayer)obj.GetValue(ClickSoundProperty);}public static void SetClickSound(DependencyObject obj, MediaPlayer value){obj.SetValue(ClickSoundProperty, value);}public static readonly DependencyProperty ClickSoundProperty =DependencyProperty.RegisterAttached("ClickSound", typeof(MediaPlayer), typeof(SoundBehavior), new PropertyMetadata(null, OnClickSoundChanged));private static void OnClickSoundChanged(DependencyObject d, DependencyPropertyChangedEventArgs e){if (d is Button button){button.Click -= Button_Click;if (e.NewValue != null){button.Click += Button_Click;}}}private static void Button_Click(object sender, RoutedEventArgs e){if (sender is Button button){var player = GetClickSound(button);if (player != null){player.Position = TimeSpan.Zero;player.Play();}}}#endregion#region HoverSound 附加属性public static MediaPlayer GetHoverSound(DependencyObject obj){return (MediaPlayer)obj.GetValue(HoverSoundProperty);}public static void SetHoverSound(DependencyObject obj, MediaPlayer value){obj.SetValue(HoverSoundProperty, value);}public static readonly DependencyProperty HoverSoundProperty =DependencyProperty.RegisterAttached("HoverSound", typeof(MediaPlayer), typeof(SoundBehavior), new PropertyMetadata(null, OnHoverSoundChanged));private static void OnHoverSoundChanged(DependencyObject d, DependencyPropertyChangedEventArgs e){if (d is Button button){button.MouseEnter -= Button_MouseEnter;if (e.NewValue != null){button.MouseEnter += Button_MouseEnter;}}}private static void Button_MouseEnter(object sender, MouseEventArgs e){if (sender is Button button){var player = GetHoverSound(button);if (player != null){player.Position = TimeSpan.Zero;player.Play();}}}#endregion}
}
MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;namespace ButtonClickSound
{public partial class MainWindow : Window{// 全局音效播放器private MediaPlayer _globalClickPlayer = new MediaPlayer();// 随机音效列表private List<MediaPlayer> _randomSounds = new List<MediaPlayer>();private Random _random = new Random();// 静音状态private bool _isMuted = false;public ICommand PlaySoundCommand { get; }public MainWindow(){InitializeComponent();LoadSounds();// 初始化命令PlaySoundCommand = new RelayCommand(ExecutePlaySound);DataContext = this;}private void LoadSounds(){try{// 初始化全局点击音效_globalClickPlayer.Open(new Uri("sounds/click.wav", UriKind.Relative));_globalClickPlayer.Volume = 0.7;// 初始化随机音效_randomSounds.Add(CreateSoundPlayer("sounds/click1.wav", 0.7));_randomSounds.Add(CreateSoundPlayer("sounds/click2.wav", 0.6));_randomSounds.Add(CreateSoundPlayer("sounds/click3.wav", 0.8));_randomSounds.Add(CreateSoundPlayer("sounds/click4.wav", 0.5));}catch (Exception ex){MessageBox.Show($"加载音效失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);}}private MediaPlayer CreateSoundPlayer(string path, double volume){var player = new MediaPlayer();player.Open(new Uri(path, UriKind.Relative));player.Volume = volume;return player;}#region 简单实现方法// 方法1: 直接在事件处理器中播放音效private void ButtonWithEventHandler_Click(object sender, RoutedEventArgs e){PlayGlobalClickSound();}// 方法2: 使用命令播放音效private void ExecutePlaySound(){PlayGlobalClickSound();}#endregion#region 高级实现方法// 自定义音效按钮private void CustomSoundButton_Click(object sender, RoutedEventArgs e){// 创建临时音效播放器var player = new MediaPlayer();player.Open(new Uri("sounds/special_click.wav", UriKind.Relative));player.Volume = 0.8;player.Play();// 播放完成后自动释放资源player.MediaEnded += (s, args) => player.Close();}// 随机音效按钮private void RandomSoundButton_Click(object sender, RoutedEventArgs e){if (_randomSounds.Count == 0) return;int index = _random.Next(0, _randomSounds.Count);var player = _randomSounds[index];player.Position = TimeSpan.Zero;player.Play();}#endregion#region 控制面板方法private void PlaySound_Click(object sender, RoutedEventArgs e){PlayGlobalClickSound();}private void StopAllSounds_Click(object sender, RoutedEventArgs e){_globalClickPlayer.Stop();foreach (var player in _randomSounds){player.Stop();}}private void ToggleMute_Click(object sender, RoutedEventArgs e){_isMuted = !_isMuted;// 设置全局音量double volume = _isMuted ? 0.0 : 0.7;_globalClickPlayer.Volume = volume;foreach (var player in _randomSounds){player.Volume = volume;}// 更新按钮文本((Button)sender).Content = _isMuted ? "取消静音" : "切换静音模式";}#endregionprivate void PlayGlobalClickSound(){_globalClickPlayer.Position = TimeSpan.Zero;_globalClickPlayer.Play();}}// 命令实现public class RelayCommand : ICommand{private readonly Action _execute;private readonly Func<bool> _canExecute;public event EventHandler CanExecuteChanged{add { CommandManager.RequerySuggested += value; }remove { CommandManager.RequerySuggested -= value; }}public RelayCommand(Action execute, Func<bool> canExecute = null){_execute = execute ?? throw new ArgumentNullException(nameof(execute));_canExecute = canExecute;}public bool CanExecute(object parameter) => _canExecute?.Invoke() ?? true;public void Execute(object parameter) => _execute();}
}
实现方法详解
1. 简单实现方法
方法1: 直接在事件处理器中播放音效
private void ButtonWithEventHandler_Click(object sender, RoutedEventArgs e)
{// 创建或使用全局播放器var player = new MediaPlayer();player.Open(new Uri("sounds/click.wav", UriKind.Relative));player.Play();// 或者使用全局播放器_globalClickPlayer.Position = TimeSpan.Zero;_globalClickPlayer.Play();
}
方法2: 使用附加行为
<Button Content="使用行为" local:SoundBehavior.ClickSound="{StaticResource ClickSoundPlayer}"/>
2. 高级实现方法
悬停+点击音效组合
<Button Content="悬停+点击音效" local:SoundBehavior.HoverSound="{StaticResource HoverSoundPlayer}"local:SoundBehavior.ClickSound="{StaticResource ClickSoundPlayer}"/>
自定义音效
private void CustomSoundButton_Click(object sender, RoutedEventArgs e)
{// 创建临时音效播放器var player = new MediaPlayer();player.Open(new Uri("sounds/special_click.wav", UriKind.Relative));player.Play();// 播放完成后自动释放资源player.MediaEnded += (s, args) => player.Close();
}
随机音效
private void RandomSoundButton_Click(object sender, RoutedEventArgs e)
{if (_randomSounds.Count == 0) return;int index = _random.Next(0, _randomSounds.Count);var player = _randomSounds[index];player.Position = TimeSpan.Zero;player.Play();
}
3. 使用命令实现
public ICommand PlaySoundCommand { get; }public MainWindow()
{PlaySoundCommand = new RelayCommand(ExecutePlaySound);
}private void ExecutePlaySound()
{PlayGlobalClickSound();
}// XAML
<Button Content="使用命令" Command="{Binding PlaySoundCommand}"/>
高级功能实现
1. 音效管理
// 全局音效管理器
public static class SoundManager
{private static readonly Dictionary<string, MediaPlayer> _sounds = new Dictionary<string, MediaPlayer>();private static double _globalVolume = 0.7;private static bool _isMuted = false;public static void LoadSound(string name, string path, double volume = 1.0){if (_sounds.ContainsKey(name)) return;var player = new MediaPlayer();player.Open(new Uri(path, UriKind.Relative));player.Volume = volume * _globalVolume;_sounds[name] = player;}public static void PlaySound(string name){if (_isMuted || !_sounds.TryGetValue(name, out var player)) return;player.Position = TimeSpan.Zero;player.Play();}public static void SetGlobalVolume(double volume){_globalVolume = volume;foreach (var player in _sounds.Values){player.Volume = volume;}}public static void SetMute(bool isMuted){_isMuted = isMuted;}
}// 使用
SoundManager.LoadSound("click", "sounds/click.wav", 0.7);
SoundManager.PlaySound("click");
2. 3D音效效果
private void PlayPositionalSound(Point position)
{// 计算相对于窗口中心的位置double centerX = ActualWidth / 2;double centerY = ActualHeight / 2;// 计算相对位置 (-1 到 1)double relX = (position.X - centerX) / centerX;double relY = (position.Y - centerY) / centerY;// 创建音效播放器var player = new MediaPlayer();player.Open(new Uri("sounds/click.wav", UriKind.Relative));// 应用平衡效果 (左右声道)player.Balance = Math.Clamp(relX, -1.0, 1.0);// 应用音量衰减double distance = Math.Sqrt(relX * relX + relY * relY);player.Volume = Math.Clamp(1.0 - distance * 0.5, 0.2, 1.0);player.Play();
}
3. 音效池系统
public class SoundPool
{private readonly List<MediaPlayer> _players = new List<MediaPlayer>();private readonly string _soundPath;private readonly double _volume;private int _currentIndex = 0;public SoundPool(string soundPath, int poolSize = 5, double volume = 1.0){_soundPath = soundPath;_volume = volume;// 初始化播放器池for (int i = 0; i < poolSize; i++){var player = new MediaPlayer();player.Open(new Uri(soundPath, UriKind.Relative));player.Volume = volume;_players.Add(player);}}public void Play(){// 选择下一个播放器var player = _players[_currentIndex];// 重置位置player.Position = TimeSpan.Zero;player.Play();// 移动到下一个播放器_currentIndex = (_currentIndex + 1) % _players.Count;}
}// 使用
private SoundPool _clickSoundPool = new SoundPool("sounds/click.wav", 5, 0.7);private void Button_Click(object sender, RoutedEventArgs e)
{_clickSoundPool.Play();
}
专业建议
1. 音效文件处理
- 使用16位PCM WAV格式以获得最佳兼容性
- 保持音效文件短小(通常小于500ms)
- 使用44.1kHz采样率
- 预加载常用音效以减少延迟
2. 性能优化
// 预加载音效
private void PreloadSounds()
{// 使用后台线程预加载Task.Run(() =>{var player = new MediaPlayer();player.Open(new Uri("sounds/click.wav", UriKind.Relative));// 预读到内存player.Play();player.Pause();player.Position = TimeSpan.Zero;});
}// 使用NAudio进行低延迟播放
private void PlayLowLatencySound(string path)
{using (var audioFile = new AudioFileReader(path))using (var outputDevice = new WaveOutEvent()){outputDevice.Init(audioFile);outputDevice.Play();}
}
3. 无障碍支持
// 检查用户是否启用了声音
private bool IsSoundEnabled()
{// 检查系统设置bool systemSoundEnabled = SystemParameters.ClientAudioPlayback;// 检查用户偏好bool userPreference = Properties.Settings.Default.SoundEnabled;return systemSoundEnabled && userPreference;
}// 提供视觉反馈替代
private void PlaySoundWithVisualFeedback()
{if (IsSoundEnabled()){PlayGlobalClickSound();}else{// 提供视觉反馈var button = sender as Button;var originalBrush = button.Background;button.Background = Brushes.Gray;// 短暂延迟后恢复Task.Delay(100).ContinueWith(_ => {Dispatcher.Invoke(() => button.Background = originalBrush);});}
}
这个实现提供了多种按钮点击音效的实现方式,从简单的直接事件处理到高级的音效管理系统和3D音效效果。您可以根据项目需求选择合适的实现方法,
相关文章:
WPF 按钮点击音效实现
WPF 按钮点击音效实现 下面我将为您提供一个完整的 WPF 按钮点击音效实现方案,包含多种实现方式和高级功能: 完整实现方案 MainWindow.xaml <Window x:Class"ButtonClickSound.MainWindow"xmlns"http://schemas.microsoft.com/win…...

编写测试用例
测试用例(Test Case)是用于测试系统的要素集合 目录 编写测试用例作用 编写测试用例要包含七大元素 测试用例的设计方法 1、等价类法 2、边界值法 3、正交表法 4、判定表法 5、错误推测法 6、场景法 编写测试用例作用 1、确保功能全面覆盖…...
解释程序(Python)不需要生成机器码 逐行解析 逐行执行
在计算机组成原理中,解释程序(Interpreter)通常不会生成独立的机器码,但具体情况取决于解释器的实现方式。以下是详细分析: 1. 传统解释程序:不生成机器码 直接逐行执行: 经典的解释器ÿ…...

每日Prompt:隐形人
提示词 黑色棒球帽,白色抹胸、粉色低腰短裙、白色襪子,黑色鞋子,粉紅色背包,衣服悬浮在空中呈现动态姿势,虚幻引擎渲染风格,高清晰游戏CG质感,户外山林背景,画面聚焦在漂浮的衣服上…...

TensorFlow深度学习实战(19)——受限玻尔兹曼机
TensorFlow深度学习实战(19)——受限玻尔兹曼机 0. 前言1. 受限玻尔兹曼机1.1 受限玻尔兹曼机架构1.2 受限玻尔兹曼机的数学原理 2. 使用受限玻尔兹曼机重建图像3. 深度信念网络小结系列链接 0. 前言 受限玻尔兹曼机 (Restricted Boltzmann Machine, RB…...

告别手动绘图!基于AI的Smart Mermaid自动可视化图表工具搭建与使用指南
以下是对Smart Mermaid的简单介绍: 一款基于 AI 技术的 Web 应用程序,可将文本内容智能转换为 Mermaid 格式的代码,并将其渲染成可视化图表可以智能制作流程图、序列图、甘特图、状态图等等,并且支持在线调整、图片导出可以Docke…...

【Oracle】安装单实例
个人主页:Guiat 归属专栏:Oracle 文章目录 1. 安装前的准备工作1.1 硬件和系统要求1.2 检查系统环境1.3 下载Oracle软件 2. 系统配置2.1 创建Oracle用户和组2.2 配置内核参数2.3 配置用户资源限制2.4 安装必要的软件包 3. 目录结构和环境变量3.1 创建Ora…...
C++测开,自动化测试,业务(第一段实习)
目录 🌼前言 一,实习经历怎么写简历 🌹业务理解 🎂结构化表达 二,实习 🦂技术和流程卡点 🔑实习收获 / 代码风格 三,测试理论,用例设计,工具链 &…...

QT中更新或添加组件时出现“”qt操作至少需要一个处于启用状态的有效资料档案库“解决方法”
在MaintenanceTool.exe中点击下一步 第一个: 第二个: 第三个: 以上任意一个放入资料库中...

论文速读《UAV-Flow Colosseo: 自然语言控制无人机系统》
论文链接:https://arxiv.org/abs/2505.15725项目主页:https://prince687028.github.io/UAV-Flow/ 0. 简介 近年来,无人机技术蓬勃发展,但如何让无人机像智能助手一样理解并执行人类语言指令,仍是一个前沿挑战。现有研…...

ES6+中Promise 中错误捕捉详解——链式调用catch()或者async/await+try/catch
通过 unhandledrejection 捕捉未处理的 Promise 异常,手动将其抛出,最终让 window.onerror 捕捉,从而统一所有异常的处理逻辑 规范代码:catch(onRejected)、async...awaittry...catch 在 JavaScript 的 Pro…...
CDN安全加速:HTTPS加密最佳配置方案
CDN安全加速的HTTPS加密最佳配置方案需从证书管理、协议优化、安全策略到性能调优进行全链路设计,以下是核心实施步骤与注意事项: 一、证书配置与管理 证书选择与格式 证书类型:优先使用受信任CA机构颁发的DV/OV/EV证…...

解常微分方程组
Euler法 function euler_method % 参数设置 v_missile 450; % 导弹速度 km/h v_enemy 90; % 敌艇速度 km/h % 初始条件 x0 0; % 导弹初始位置 x y0 0; % 导弹初始位置 y xe0 120; % 敌艇初始位置 y t0 0; % 初始时间 % 时间步长和总时间 dt 0.01; % 时间步长 t_final …...

C++实现汉诺塔游戏自动完成
目录 一、汉诺塔的规则二、数学递归推导式三、步骤实现(一)汉诺塔模型(二)递归实现(三)显示1.命令行显示2.SDL图形显示 四、处理用户输入及SDL环境配置五、总结六、源码下载 一、汉诺塔的规则 游戏由3根柱子和若干大小不一的圆盘组成,初始状态下,所有的…...
在 ABP VNext 中集成 Serilog:打造可观测、结构化日志系统
🚀 在 ABP VNext 中集成 Serilog:打造可观测、结构化日志系统 📚 目录 🚀 在 ABP VNext 中集成 Serilog:打造可观测、结构化日志系统1. 为什么要使用结构化日志? 🤔2. 核心集成步骤 Ὦ…...

pikachu靶场通关笔记07 XSS关卡03-存储型XSS
目录 一、XSS 二、存储型XSS 三、源码分析 四、渗透实战 1、输入mooyuan试一试 2、注入Payload 3、查看数据库 4、再次进入留言板页面 本系列为通过《pikachu靶场通关笔记》的XSS关卡(共10关)渗透集合,通过对XSS关卡源码的代码审计找到XSS风险的…...
GitLab CI、GitHub Actions和Jenkins进行比较
特性/工具JenkinsGitLab CIGitHub Actions架构设计哲学Master/Agent分布式架构,通过插件扩展功能代码与CI/CD强耦合,内置Git仓库,基于Runner注册机制事件驱动,与GitHub深度集成,基于虚拟机的Job执行单元核心运行机制支…...
strcat及其模拟实现
#define _CRT_SECURE_NO_WARNINGS strcat 追加字符串 str "string"(字符串) cat "concatenate"(连接 / 追加) char* strcat(char* destination, const char* source); strcat的应用 方法一ÿ…...

OpenCV CUDA模块直方图计算------用于在 GPU 上执行对比度受限的自适应直方图均衡类cv::cuda::CLAHE
操作系统:ubuntu22.04 OpenCV版本:OpenCV4.9 IDE:Visual Studio Code 编程语言:C11 算法描述 cv::cuda::CLAHE 是 OpenCV 的 CUDA 模块中提供的一个类,用于在 GPU 上执行对比度受限的自适应直方图均衡(Contrast Limi…...

华为OD机试真题——矩形绘制(2025A卷:200分)Java/python/JavaScript/C/C++/GO最佳实现
2025 A卷 200分 题型 本专栏内全部题目均提供Java、python、JavaScript、C、C++、GO六种语言的最佳实现方式; 并且每种语言均涵盖详细的问题分析、解题思路、代码实现、代码详解、3个测试用例以及综合分析; 本文收录于专栏:《2025华为OD真题目录+全流程解析+备考攻略+经验分…...
通义开源视觉感知多模态 RAG 推理框架 VRAG-RL:开启多模态推理新时代
通义实验室的自然语言智能团队,凭借深厚的技术积累与创新精神,成功研发并开源了视觉感知多模态 RAG 推理框架 VRAG-RL,为 AI 在复杂视觉信息处理领域带来了重大突破。 传统 RAG 方法的局限 传统的检索增强型生成(RAG࿰…...
爬虫入门:从基础到实战全攻略
🧠 一、爬虫基础概念 1.1 爬虫定义 爬虫(Web Crawler)是模拟浏览器行为,自动向服务器发送请求并获取响应数据的一种程序。主要用于从网页中提取结构化数据,供后续分析、展示或存储使用。 1.2 爬虫特点 数据碎片化&…...
qemu安装risc-V 64
参考这篇文章https://developer.aliyun.com/article/1323996,其中在wsl下面安装可能会报错环境变量中有空格。 # clean_path.sh#!/bin/bash# 备份旧 PATH OLD_PATH"$PATH"# 过滤掉包含空格、制表符、换行的路径 CLEAN_PATH"" IFS: read -ra PA…...

JDBC连不上mysql:Unable to load authentication plugin ‘caching_sha2_password‘.
最近为一个spring-boot项目下了mysql-9.3.0,结果因为mysql版本太新一直报错连不上。 错误如下: 2025-06-01 16:19:43.516 ERROR 22088 --- [http-nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispat…...
AsyncIOScheduler与BackgroundScheduler的线程模型对比
1. BackgroundScheduler的线程机制 多线程模型:BackgroundScheduler基于线程池执行任务,默认通过ThreadPoolExecutor创建独立线程处理任务,每个任务运行在单独的线程中,主线程不会被阻塞。适用场景:适合同步…...
Python+MongoDb使用手册(精简)
这里是学了下面链接的内容,加上一些自己学习的内容综合的,大家也可以去看看这篇文章,写的特别好 【python】在Python中操作MongoDB的详细用法教程与实战案例分享_python轻松入门,基础语法到高阶实战教学-CSDN专栏 1 库࿱…...
前端面经 协商缓存和强缓存
HHTTPTTP缓存 协商缓存和强缓存 核心区别是否向服务器发起请求验证资源过期 强缓存 浏览器直接读取本地缓存,不发请求 HTTP响应头 Cache-Control:max-age3600资源有效期 Expires优先级低 如果有效浏览器返回200(浏览器换伪造的200) 应用静态资源 协商缓存 OK如果 1强缓…...

MacOS安装Docker Desktop并汉化
1. 安装Docker Desktop 到Docker Desktop For Mac下载对应系统的Docker Desktop 安装包,下载后安装,没有账号需要注册,然后登陆即可。 2. 汉化 前往汉化包下载链接下载对应系统的.asar文件 然后将安装好的文件覆盖原先的文件app.asar文件…...

Centos系统搭建主备DNS服务
目录 一、主DNS服务器配置 1.安装 BIND 软件包 2.配置主配置文件 3.创建正向区域文件 4.创建区域数据文件 5.检查配置语法并重启服务 二、从DNS服务配置 1.安装 BIND 软件包 2.配置主配置文件 3.创建缓存目录 4.启动并设置开机自启 一、主DNS服务器配置 1.安装 BIN…...
VUE项目部署IIS服务器手册
IIS部署Vue项目完整手册 📋 目录 基础概念准备工作Vue项目构建web.config详解IIS部署步骤不同场景配置常见问题实用配置模板 基础概念 Vue单页应用(SPA)工作原理 重要理解:Vue项目是单页应用,这意味着:…...