WPF实战项目十八(客户端):添加新增、查询、编辑功能

1、ToDoView.xmal添加引用,添加微软的行为类

 xmlns:i="http://schemas.microsoft.com/xaml/behaviors"

2、给项目添加行为

<i:Interaction.Triggers><i:EventTrigger EventName="MouseLeftButtonUp"><i:InvokeCommandAction Command="{Binding DataContext.SelectedCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}" CommandParameter="{Binding}" /></i:EventTrigger></i:Interaction.Triggers>

3、ToDoViewModel.cs新建查询SelectedCommand

public DelegateCommand<ToDoDto> SelectedCommand { get;private set; }public ToDoViewModel(IToDoService toDoService, IContainerProvider provider) : base(provider){ToDoDtos = new ObservableCollection<ToDoDto>();AddCommand = new DelegateCommand(Add);SelectedCommand = new DelegateCommand<ToDoDto>(Selected);this.toDoService = toDoService;}
private async void Selected(ToDoDto obj){try{UpdateLoading(true);var todoResult = await toDoService.GetFirstOfDefaultAsync(obj.Id);if (todoResult.Status){IsIsRightDrawerOpens = true;CurrentDto = todoResult.Result;}}catch (Exception){throw;}finally{UpdateLoading(false);}}

4、新建属性编辑选中/新增时的对象

private ToDoDto currentDto;/// <summary>/// 编辑选中/新增时的对象/// </summary>public ToDoDto CurrentDto{get { return currentDto; }set { currentDto = value; RaisePropertyChanged(); }}

5、前台绑定文本标题、内容、状态

                    <StackPanelMargin="20"DockPanel.Dock="Top"Orientation="Horizontal"><TextBlock VerticalAlignment="Center" Text="状态:" /><ComboBox SelectedIndex="{Binding CurrentDto.Status}"><ComboBoxItem>待办</ComboBoxItem><ComboBoxItem>已完成</ComboBoxItem></ComboBox></StackPanel><TextBoxMargin="20,5"md:HintAssist.Hint="请输入待办概要"DockPanel.Dock="Top"Text="{Binding CurrentDto.Title}" /><TextBoxMinHeight="100"Margin="20,10"md:HintAssist.Hint="请输入待办事项内容"DockPanel.Dock="Top"Text="{Binding CurrentDto.Content}" />

6、F5运行项目,点击待办事项能在右侧显示信息

7、绑定搜索输入框,首先定义一个属性,前台绑定输入框的值Search,给输入框添加回车事件

        private string search;/// <summary>/// 搜索条件/// </summary>public string Search{get { return search; }set { search = value; RaisePropertyChanged(); }}
<TextBoxWidth="250"md:HintAssist.Hint="查找待办事项..."md:TextFieldAssist.HasClearButton="True"Text="{Binding Search, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"><TextBox.InputBindings><KeyBinding Key="Enter" Command="{Binding SearchCommand}" /></TextBox.InputBindings></TextBox>

8、SearchCommand搜索事件可以和上面AddCommand合并到一起,【添加待办】按钮设置事件:ExecuteCommand,参数设置="新增",查找框设置成ExecuteCommand,参数设置="查询"

public DelegateCommand<string> ExecuteCommand { get; private set; }public ToDoViewModel(IToDoService toDoService, IContainerProvider provider) : base(provider){ToDoDtos = new ObservableCollection<ToDoDto>();ExecuteCommand = new DelegateCommand<string>(Execute);SelectedCommand = new DelegateCommand<ToDoDto>(Selected);this.toDoService = toDoService;}
                <ButtonMargin="10,0"HorizontalAlignment="Right"Command="{Binding ExecuteCommand}"CommandParameter="新增"Content="+ 添加待办" />
<TextBoxWidth="250"md:HintAssist.Hint="查找待办事项..."md:TextFieldAssist.HasClearButton="True"Text="{Binding Search, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"><TextBox.InputBindings><KeyBindingKey="Enter"Command="{Binding ExecuteCommand}"CommandParameter="查询" /></TextBox.InputBindings></TextBox>

9、获取数据的函数里面把Search属性传进去

/// <summary>/// 获取数据/// </summary>private async void GetDataAsync(){UpdateLoading(true);var todoResult = await toDoService.GetAllPageListAsync(new WPFProjectShared.Parameters.QueryParameter{PageIndex = 0,PageSize = 100,Search = Search});if (todoResult.Status){toDoDtos.Clear();foreach (var item in todoResult.Result.Items){toDoDtos.Add(item);}}UpdateLoading(false);}

10、新增Excute方法和Query方法

private void Execute(string obj){switch (obj){case "新增":Add();break;case "查询":Query();break;}}private void Query(){GetDataAsync();}

11、F5运行项目,在搜索框里面查询显示12、【保存】事件,按钮添加绑定事件,修改Excute方法、新增Add方法和Save方法

                    <ButtonMargin="20,0"Command="{Binding ExecuteCommand}"CommandParameter="保存"Content="添加到待办"DockPanel.Dock="Top" />
        private void Execute(string obj){switch (obj){case "新增":Add();break;case "查询":Query();break;case "保存":Save();break;}}/// <summary>/// 添加待办/// </summary>/// <exception cref="NotImplementedException"></exception>private void Add(){CurrentDto = new ToDoDto();IsIsRightDrawerOpens = true;}
private async void Save(){if (string.IsNullOrWhiteSpace(CurrentDto.Title) || string.IsNullOrWhiteSpace(CurrentDto.Content)){return;}else{UpdateLoading(true);try{if (CurrentDto.Id > 0)//update{var updateResult = await toDoService.UpdateAsync(CurrentDto);if (updateResult.Status){var todo = ToDoDtos.FirstOrDefault(t => t.Id == CurrentDto.Id);if (todo != null){todo.Title = CurrentDto.Title;todo.Content = CurrentDto.Content;todo.Status = CurrentDto.Status;}}IsIsRightDrawerOpens = false;}else//add{var addResult = await toDoService.AddAsync(CurrentDto);if (addResult.Status){ToDoDtos.Add(addResult.Result);IsIsRightDrawerOpens = false;}}}catch (Exception){throw;}finally { UpdateLoading(false); }}}

修改API中TodoController的代码

        [HttpPost]public async Task<ApiResponse> Update(TodoDto toDo){return await toDoService.UpdateEntityAsync(toDo);}

13、F5运行项目,测试修改待办

保存的时候报错:

{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1","title":"One or more validation errors occurred.","status":400,"traceId":"00-40d7073ee1cf77c77875996f55f65034-4888403c8bef54ca-00","errors":{"toDo":["The toDo field is required."],"$.Status":["The JSON value could not be converted to System.String. Path: $.Status | LineNumber: 0 | BytePositionInLine: 59."]}}

后来发现是实体类引用错误导致,重新引用WPFProjectShared.Dtos.TodoDto,

另外一个报错:

{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1","title":"One or more validation errors occurred.","status":400,"traceId":"00-25e255d827e2947f869ccba30a1714e4-b2423a142252e535-00","errors":{"$":["'-' is invalid within a number, immediately after a sign character ('+' or '-'). Expected a digit ('0'-'9'). Path: $ | LineNumber: 0 | BytePositionInLine: 1."],"toDo":["The toDo field is required."]}}

修改请求参数的格式application/json

ToDoView.xmal完整代码:

<UserControlx:Class="WPFProject.Views.ToDoView"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:i="http://schemas.microsoft.com/xaml/behaviors"xmlns:local="clr-namespace:WPFProject.Views"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"d:DesignHeight="450"d:DesignWidth="800"mc:Ignorable="d"><md:DialogHost><md:DrawerHost IsRightDrawerOpen="{Binding IsIsRightDrawerOpens}"><md:DrawerHost.RightDrawerContent><DockPanel Width="300" LastChildFill="False"><TextBlockPadding="20,10"DockPanel.Dock="Top"FontSize="20"FontWeight="Bold"Text="添加待办" /><StackPanelMargin="20"DockPanel.Dock="Top"Orientation="Horizontal"><TextBlock VerticalAlignment="Center" Text="状态:" /><ComboBox SelectedIndex="{Binding CurrentDto.Status}"><ComboBoxItem>待办</ComboBoxItem><ComboBoxItem>已完成</ComboBoxItem></ComboBox></StackPanel><TextBoxMargin="20,5"md:HintAssist.Hint="请输入待办概要"DockPanel.Dock="Top"Text="{Binding CurrentDto.Title}" /><TextBoxMinHeight="100"Margin="20,10"md:HintAssist.Hint="请输入待办事项内容"DockPanel.Dock="Top"Text="{Binding CurrentDto.Content}" /><ButtonMargin="20,0"Command="{Binding ExecuteCommand}"CommandParameter="保存"Content="添加到待办"DockPanel.Dock="Top" /></DockPanel></md:DrawerHost.RightDrawerContent><Grid><Grid.RowDefinitions><RowDefinition Height="auto" /><RowDefinition /></Grid.RowDefinitions><StackPanelMargin="15,15,0,0"VerticalAlignment="Center"Orientation="Horizontal"><TextBoxWidth="250"md:HintAssist.Hint="查找待办事项..."md:TextFieldAssist.HasClearButton="True"Text="{Binding Search, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"><TextBox.InputBindings><KeyBindingKey="Enter"Command="{Binding ExecuteCommand}"CommandParameter="查询" /></TextBox.InputBindings></TextBox><TextBlockMargin="10,0,5,0"VerticalAlignment="Center"Text="筛选:" /><ComboBox Width="80" SelectedIndex="0"><ComboBoxItem>全部</ComboBoxItem><ComboBoxItem>待办</ComboBoxItem><ComboBoxItem>已完成</ComboBoxItem></ComboBox></StackPanel><ButtonMargin="10,0"HorizontalAlignment="Right"Command="{Binding ExecuteCommand}"CommandParameter="新增"Content="+ 添加待办" /><ScrollViewer Grid.Row="1"><ItemsControlGrid.Row="1"Margin="0,20"HorizontalAlignment="Center"ItemsSource="{Binding ToDoDtos}"><ItemsControl.ItemsPanel><ItemsPanelTemplate><WrapPanel /></ItemsPanelTemplate></ItemsControl.ItemsPanel><ItemsControl.ItemTemplate><DataTemplate><md:TransitioningContent OpeningEffect="{md:TransitionEffect Kind=ExpandIn}"><GridWidth="220"MinHeight="180"MaxHeight="250"Margin="8"><i:Interaction.Triggers><i:EventTrigger EventName="MouseLeftButtonUp"><i:InvokeCommandAction Command="{Binding DataContext.SelectedCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}" CommandParameter="{Binding}" /></i:EventTrigger></i:Interaction.Triggers><Grid.RowDefinitions><RowDefinition Height="auto" /><RowDefinition /></Grid.RowDefinitions><md:PopupBox HorizontalAlignment="Right" Panel.ZIndex="1"><Button Content="删除" /></md:PopupBox><BorderGrid.RowSpan="2"Background="#10B136"CornerRadius="5" /><TextBlockPadding="10,5"FontWeight="Bold"Text="{Binding Title}" /><TextBlockGrid.Row="1"Padding="10,5"Text="{Binding Content}" /><Canvas Grid.RowSpan="2" ClipToBounds="True"><!--  切割  --><BorderCanvas.Top="20"Canvas.Right="-80"Width="120"Height="120"Background="#FFFFFF"CornerRadius="60"Opacity="0.1" /><BorderCanvas.Top="100"Canvas.Right="-40"Width="140"Height="140"Background="#FFFFFF"CornerRadius="70"Opacity="0.1" /></Canvas></Grid></md:TransitioningContent></DataTemplate></ItemsControl.ItemTemplate></ItemsControl></ScrollViewer></Grid></md:DrawerHost></md:DialogHost>
</UserControl>

 ToDoViewModel.cs完整代码

using Prism.Commands;
using Prism.Ioc;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WPFProject.Common.Models;
using WPFProject.Service;
using WPFProjectShared.Dtos;namespace WPFProject.ViewModels
{public class ToDoViewModel : NavigationViewModel{private readonly IToDoService toDoService;public ToDoViewModel(IToDoService toDoService, IContainerProvider provider) : base(provider){ToDoDtos = new ObservableCollection<TodoDto>();ExecuteCommand = new DelegateCommand<string>(Execute);SelectedCommand = new DelegateCommand<TodoDto>(Selected);this.toDoService = toDoService;}private void Execute(string obj){switch (obj){case "新增":Add();break;case "查询":Query();break;case "保存":Save();break;}}private async void Save(){if (string.IsNullOrWhiteSpace(CurrentDto.Title) || string.IsNullOrWhiteSpace(CurrentDto.Content)){return;}else{UpdateLoading(true);try{if (CurrentDto.Id > 0)//update{var updateResult = await toDoService.UpdateAsync(CurrentDto);if (updateResult.Status){var todo = ToDoDtos.FirstOrDefault(t => t.Id == CurrentDto.Id);if (todo != null){todo.Title = CurrentDto.Title;todo.Content = CurrentDto.Content;todo.Status = CurrentDto.Status;}}IsIsRightDrawerOpens = false;}else//add{var addResult = await toDoService.AddAsync(CurrentDto);if (addResult.Status){ToDoDtos.Add(addResult.Result);IsIsRightDrawerOpens = false;}}}catch (Exception){throw;}finally { UpdateLoading(false); }}}private void Query(){GetDataAsync();}/// <summary>/// 添加待办/// </summary>/// <exception cref="NotImplementedException"></exception>private void Add(){CurrentDto = new TodoDto();IsIsRightDrawerOpens = true;}private async void Selected(TodoDto obj){try{UpdateLoading(true);var todoResult = await toDoService.GetFirstOfDefaultAsync(obj.Id);if (todoResult.Status){IsIsRightDrawerOpens = true;CurrentDto = todoResult.Result;}}catch (Exception){throw;}finally{UpdateLoading(false);}}public DelegateCommand<string> ExecuteCommand { get; private set; }public DelegateCommand<TodoDto> SelectedCommand { get;private set; }private bool isIsRightDrawerOpens;/// <summary>/// 右侧新增窗口是否打开/// </summary>public bool IsIsRightDrawerOpens{get { return isIsRightDrawerOpens; }set { isIsRightDrawerOpens = value; RaisePropertyChanged(); }}private TodoDto currentDto;/// <summary>/// 编辑选中/新增时的对象/// </summary>public TodoDto CurrentDto{get { return currentDto; }set { currentDto = value; RaisePropertyChanged(); }}private string search;/// <summary>/// 搜索条件/// </summary>public string Search{get { return search; }set { search = value; RaisePropertyChanged(); }}private ObservableCollection<TodoDto> toDoDtos;public ObservableCollection<TodoDto> ToDoDtos{get { return toDoDtos; }set { toDoDtos = value; }}/// <summary>/// 获取数据/// </summary>private async void GetDataAsync(){UpdateLoading(true);var todoResult = await toDoService.GetAllPageListAsync(new WPFProjectShared.Parameters.QueryParameter{PageIndex = 0,PageSize = 100,Search = Search});if (todoResult.Status){toDoDtos.Clear();foreach (var item in todoResult.Result.Items){toDoDtos.Add(item);}}UpdateLoading(false);}public override void OnNavigatedTo(NavigationContext navigationContext){base.OnNavigatedTo(navigationContext);GetDataAsync();}}
}

备忘录也相应修改,完整代码如下:

MemoView.xmal

<UserControlx:Class="WPFProject.Views.MemoView"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:i="http://schemas.microsoft.com/xaml/behaviors"xmlns:local="clr-namespace:WPFProject.Views"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"d:DesignHeight="450"d:DesignWidth="800"mc:Ignorable="d"><md:DialogHost><md:DrawerHost IsRightDrawerOpen="{Binding IsIsRightDrawerOpens}"><md:DrawerHost.RightDrawerContent><DockPanel Width="300" LastChildFill="False"><TextBlockPadding="20,10"DockPanel.Dock="Top"FontSize="20"FontWeight="Bold"Text="添加备忘录" /><TextBoxMargin="20,5"md:HintAssist.Hint="请输入备忘录概要"DockPanel.Dock="Top"Text="{Binding CurrentDto.Title}" /><TextBoxMinHeight="100"Margin="20,10"md:HintAssist.Hint="请输入备忘录内容"DockPanel.Dock="Top"Text="{Binding CurrentDto.Content}" /><ButtonMargin="20,0"Command="{Binding ExecuteCommand}"CommandParameter="保存"Content="添加到备忘录"DockPanel.Dock="Top" /></DockPanel></md:DrawerHost.RightDrawerContent><Grid><Grid.RowDefinitions><RowDefinition Height="auto" /><RowDefinition /></Grid.RowDefinitions><StackPanelMargin="15,15,0,0"VerticalAlignment="Center"Orientation="Horizontal"><TextBoxWidth="250"md:HintAssist.Hint="查找备忘录..."md:TextFieldAssist.HasClearButton="True"Text="{Binding Search, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"><TextBox.InputBindings><KeyBindingKey="Enter"Command="{Binding ExecuteCommand}"CommandParameter="查询" /></TextBox.InputBindings></TextBox></StackPanel><ButtonMargin="10,0"HorizontalAlignment="Right"Command="{Binding ExecuteCommand}"CommandParameter="新增"Content="+ 添加备忘录" /><ScrollViewer Grid.Row="1"><ItemsControlMargin="0,20"HorizontalAlignment="Center"ItemsSource="{Binding MemoDtos}"><ItemsControl.ItemsPanel><ItemsPanelTemplate><WrapPanel /></ItemsPanelTemplate></ItemsControl.ItemsPanel><ItemsControl.ItemTemplate><DataTemplate><md:TransitioningContent OpeningEffect="{md:TransitionEffect Kind=ExpandIn}"><GridWidth="220"MinHeight="180"MaxHeight="250"Margin="8"><i:Interaction.Triggers><i:EventTrigger EventName="MouseLeftButtonUp"><i:InvokeCommandAction Command="{Binding DataContext.SelectedCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}" CommandParameter="{Binding}" /></i:EventTrigger></i:Interaction.Triggers><Grid.RowDefinitions><RowDefinition Height="auto" /><RowDefinition /></Grid.RowDefinitions><md:PopupBox HorizontalAlignment="Right" Panel.ZIndex="1"><Button Content="删除" /></md:PopupBox><BorderGrid.RowSpan="2"Background="#10B136"CornerRadius="5" /><TextBlockPadding="10,5"FontWeight="Bold"Text="{Binding Title}" /><TextBlockGrid.Row="1"Padding="10,5"Text="{Binding Content}" /><Canvas Grid.RowSpan="2" ClipToBounds="True"><!--  切割  --><BorderCanvas.Top="20"Canvas.Right="-80"Width="120"Height="120"Background="#FFFFFF"CornerRadius="60"Opacity="0.1" /><BorderCanvas.Top="100"Canvas.Right="-40"Width="140"Height="140"Background="#FFFFFF"CornerRadius="70"Opacity="0.1" /></Canvas></Grid></md:TransitioningContent></DataTemplate></ItemsControl.ItemTemplate></ItemsControl></ScrollViewer></Grid></md:DrawerHost></md:DialogHost>
</UserControl>

 MemoViewModel.cs

using Prism.Commands;
using Prism.Ioc;
using Prism.Regions;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using WPFProject.Common.Models;
using WPFProject.Service;
using WPFProjectShared.Dtos;namespace WPFProject.ViewModels
{public class MemoViewModel : NavigationViewModel{private readonly IMemoService memoService;public MemoViewModel(IMemoService memoService, IContainerProvider provider) : base(provider){MemoDtos = new ObservableCollection<MemoDto>();ExecuteCommand = new DelegateCommand<string>(Execute);SelectedCommand = new DelegateCommand<MemoDto>(Selected);this.memoService = memoService;}private void Execute(string obj){switch (obj){case "新增":Add();break;case "查询":Query();break;case "保存":Save();break;}}private async void Save(){if (string.IsNullOrWhiteSpace(CurrentDto.Title) || string.IsNullOrWhiteSpace(CurrentDto.Content)){return;}else{UpdateLoading(true);try{if (CurrentDto.Id > 0)//update{var updateResult = await memoService.UpdateAsync(CurrentDto);if (updateResult.Status){var todo = MemoDtos.FirstOrDefault(t => t.Id == CurrentDto.Id);if (todo != null){todo.Title = CurrentDto.Title;todo.Content = CurrentDto.Content;}}IsIsRightDrawerOpens = false;}else//add{var addResult = await memoService.AddAsync(CurrentDto);if (addResult.Status){MemoDtos.Add(addResult.Result);IsIsRightDrawerOpens = false;}}}catch (Exception){throw;}finally { UpdateLoading(false); }}}private void Query(){GetDataAsync();}private async void Selected(MemoDto obj){try{UpdateLoading(true);var memoResult = await memoService.GetFirstOfDefaultAsync(obj.Id);if (memoResult.Status){IsIsRightDrawerOpens = true;CurrentDto = memoResult.Result;}}catch (Exception){throw;}finally{UpdateLoading(false);}}private void Add(){CurrentDto = new MemoDto();IsIsRightDrawerOpens = true;}public DelegateCommand AddCommand { get; private set; }public DelegateCommand<MemoDto> SelectedCommand { get; private set; }public DelegateCommand<string> ExecuteCommand { get; private set; }private bool isIsRightDrawerOpens;public bool IsIsRightDrawerOpens{get { return isIsRightDrawerOpens; }set { isIsRightDrawerOpens = value; RaisePropertyChanged(); }}private ObservableCollection<MemoDto> memoDtos;public ObservableCollection<MemoDto> MemoDtos{get { return memoDtos; }set { memoDtos = value; RaisePropertyChanged(); }}private MemoDto currentDto;/// <summary>/// 新增/编辑 选中数据/// </summary>public MemoDto CurrentDto{get { return currentDto; }set { currentDto = value; RaisePropertyChanged(); }}private string search;/// <summary>/// 搜索条件/// </summary>public string Search{get { return search; }set { search = value; RaisePropertyChanged(); }}private async void GetDataAsync(){UpdateLoading(true);var memoResult = await memoService.GetAllPageListAsync(new WPFProjectShared.Parameters.QueryParameter{PageIndex = 0,PageSize = 100,Search = Search});if (memoResult.Status){memoDtos.Clear();foreach (var item in memoResult.Result.Items){memoDtos.Add(item);}}UpdateLoading(false);}public override void OnNavigatedTo(NavigationContext navigationContext){base.OnNavigatedTo(navigationContext);GetDataAsync();}}
}

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

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

相关文章

maven 基础

maven常用命令 clean &#xff1a;清理 compile&#xff1a;编译 test&#xff1a;测试 package&#xff1a;打包 install&#xff1a;安装 maven坐标书写规范 <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</ar…

【JavaEE】多线程 -- 死锁问题

目录 1. 问题引入 2.死锁问题的概念和原因 3. 解决死锁问题 1. 问题引入 在学习死锁之前, 我们先观察下面的代码能否输出正确的结果: 运行程序, 能正常输出结果: 这个代码只管上看起来, 好像是有锁冲突的, 此时的 locker 对象已经是加锁的状态, 在尝试对 locker 加锁, 不应该…

什么是PDN的交流阻抗?

什么是PDN的交流阻抗&#xff1f; 在电力电子领域&#xff0c;PDN&#xff08;Power Distribution Network&#xff09;的交流阻抗是一个重要的概念&#xff0c;它反映了PDN在交流电源和负载之间传输电能的能力。了解PDN的交流阻抗对于优化电源设计、提高系统性能和可靠性具有重…

[iOS学习笔记]浅谈RunLoop底层

RunLoop是什么&#xff1f; RunLoop是iOS开发中比较重要的知识点&#xff0c;它贯穿程序运行的整个过程。它是线程基础架构的一部分&#xff0c;是一种保障线程循环处理事件而不会退出的机制。同时也负责管理线程需要处理的事件&#xff0c;让线程有事儿时忙碌&#xff0c;没事…

全网最牛最全面的Jmeter接口测试:jmeter_逻辑控制器_事务控制器

事务&#xff1a; 性能测试中&#xff0c;事务指的是从端到端&#xff0c;一个完整的操作过程&#xff0c;比如一次登录、一次 筛选条件查询&#xff0c;一次支付等&#xff1b;技术上讲&#xff1a;事务就是由1个或多个请求组成的 事务控制器 事务控制器类似简单控制器&…

spring框架的事务传播级别经典篇

一 spring事务传播级别 1.1 总结概述 方法A:外围方法&#xff0c;方法B&#xff1a;内部方法&#xff0c;在A中调用B 1.事务级别PROPAGATION_REQUIRED&#xff1a; 如果A为PROPAGATION_REQUIRED&#xff1a;B 不管有没有设置事务级别&#xff0c;都会加入到A的事务级别中。如…

科学上网也clone不全PX4?

一、问题 已经科学上网&#xff0c;下载PX4固件 git clone https://github.com/PX4/Firmware.git --recursivePX4大框架 clone 下来了&#xff0c;但是内部的子模块很多没有&#xff0c;报了很多 Fatal&#xff0c;例如 fatal: clone of https://github.com/px4/cyclonedds …

【Java线程通信】一窥究竟

今天我们要聊一聊Java线程通信。如果你是一个Java开发者&#xff0c;那么你肯定知道线程是Java中的一个重要概念。线程是程序执行的最小单位&#xff0c;它可以独立运行&#xff0c;也可以与其他线程共享资源。那么&#xff0c;线程之间如何进行通信呢&#xff1f;这就是我们今…

代理模式 1、静态代理 2、动态代理 jdk自带动态代理 3、Cglib代理

文章目录 代理模式1、静态代理2、动态代理jdk自带动态代理 3、Cglib代理 来和大家聊聊代理模式 代理模式 代理模式&#xff1a;即通过代理对象访问目标对象&#xff0c;实现目标对象的方法。这样做的好处是&#xff1a;可以在目标对象实现的基础上&#xff0c;增强额外的功能操…

EI级 | Matlab实现TCN-BiLSTM-Multihead-Attention多头注意力机制多变量时间序列预测

EI级 | Matlab实现TCN-BiLSTM-Multihead-Attention多头注意力机制多变量时间序列预测 目录 EI级 | Matlab实现TCN-BiLSTM-Multihead-Attention多头注意力机制多变量时间序列预测预测效果基本介绍程序设计参考资料 预测效果 基本介绍 1.【EI级】Matlab实现TCN-BiLSTM-Multihead-…

Containerd Container管理功能解析

Containerd Container管理功能解析 container是containerd的一个核心功能&#xff0c;用于创建和管理容器的基本信息。 本篇containerd版本为v1.7.9。 更多文章访问 https://www.cyisme.top 本文从ctr c create命令出发&#xff0c;分析containerd的容器及镜像管理相关功能。 …