.NET 6 API + Dapper + SQL Server 2014

 C# (.NET 6 API) + Dapper + SQL Server 2014及以上

Packages:

<PackageReference Include="Dapper" Version="2.0.143" />

<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />

<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />

创建ISqlConnectionResolver和他的实现类SqlConnectionResolver.cs,此方法用于在.NET6 API 中根据需要访问不通的数据库地址。

using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Configuration;namespace Data.DapperRepository
{public sealed class DBConnectionStrings{public const string DbConnectionReadOnly = "DbReadOnly";public const string DbConnectionReadWrite = "DbReadWrite";public const string ConfigurationDbConnection = "Configuration";}public interface ISqlConnectionResolver{SqlConnection GetSqlConnection(string connectionStringName);}public class SqlConnectionResolver : ISqlConnectionResolver{private readonly IConfiguration _configuration;public SqlConnectionResolver(IConfiguration configuration){_configuration = configuration;}#region Web Api Implementationpublic SqlConnection GetSqlConnection(string connectionStringName){string? connectionString = "";if (string.IsNullOrWhiteSpace(connectionStringName) || connectionStringName == DBConnectionStrings.DbConnectionReadWrite){connectionString = _configuration.GetSection("ConnectionStrings")[DBConnectionStrings.DbConnectionReadWrite];}else if (connectionStringName == DBConnectionStrings.DbConnectionReadOnly){connectionString = _configuration.GetSection("ConnectionStrings")[DBConnectionStrings.DbConnectionReadOnly];}else if (connectionStringName == DBConnectionStrings.ConfigurationDbConnection){connectionString = _configuration.GetSection("ConnectionStrings")[DBConnectionStrings.ConfigurationDbConnection];}else{connectionString = _configuration.GetSection("ConnectionStrings")[DBConnectionStrings.DbConnectionReadWrite];}return new SqlConnection(connectionString);}#endregion}}

SqlMapperExtensions.cs 用于扩张Dapper参数转换成Type类型的table(user definded table in SQL Server)。此方法用于解决 where Id in (1,2,3,...) 在 SQL server 中的限制。

/****** Object:  UserDefinedTableType [dbo].[IdTable]    Script Date: 9/20/2024 5:06:32 PM ******/
CREATE TYPE [dbo].[IdTable] AS TABLE([Id] [int] NOT NULL
)--Demo store procedure to introduce how to call UserDefinedTableType 
/* TEST BELOWDECLARE @UserIds [dbo].[IdTable]INSERT INTO @UserIdsSELECT 10INSERT INTO @UserIdsSELECT 833EXEC SP_GET_USERS_BY_IDS @UserIds*/
CREATE PROCEDURE [dbo].[SP_GET_USERS_BY_IDS]
(@UserIds [dbo].[IdTable] READONLY
)
AS
BEGINSELECT n.Id,NetWorkUserName,FirstName,LastName FROM @UserIds m join ApplicationUsers n with (nolock) on m.Id=n.Id
END

 Insert store procedure demo

/*	TEST BELOWEXEC SP_INSERT_API_AUDITTRAIL 59169,'2023-08-24 14:07',10,'Evan Test'
*/
CREATE PROCEDURE [dbo].[SP_INSERT_API_AUDITTRAIL]@UserId				int = 0,@ExecutionTime		datetime=null,@ExecutionDuration	int=0,@ServiceName		nvarchar(256)=null,@MethodName			nvarchar(256)=null,@Parameters			nvarchar(1024)=null,@ClientIpAddress	nvarchar(64)=null,@BrowserInfo		nvarchar(256)=null,@Exception			nvarchar(2000)=null,@CustomData			nvarchar(2000)=null
AS
BEGINif ISNULL(@ExecutionTime,'')=''beginset @ExecutionTime=GETUTCDATE();endinsert into AbpAuditLogs(UserId	,ExecutionTime,ExecutionDuration,ServiceName	,MethodName	,[Parameters]	,ClientIpAddress,BrowserInfo	,[Exception]	,CustomData) values(@UserId				,@ExecutionTime		,@ExecutionDuration	,@ServiceName		,@MethodName			,@Parameters			,@ClientIpAddress	,@BrowserInfo		,@Exception			,@CustomData)	END
GO
using System.Data;
using Dapper;
using System.Reflection;namespace Data.DapperRepository
{/// <summary>///  Demo: new { UserIds = userIds.AsTableValuedParameter("dbo.IdTable", new List<string>() { "Id" }), Parameter2 = parameter2 }/// </summary>public static class SqlMapperExtensions{/// <summary>/// This extension converts an enumerable set to a Dapper TVP/// </summary>/// <typeparam name="T">type of enumerbale</typeparam>/// <param name="enumerable">list of values</param>/// <param name="typeName">database type name</param>/// <param name="orderedColumnNames">if more than one column in a TVP, /// columns order must mtach order of columns in TVP</param>/// <returns>a custom query parameter</returns>public static SqlMapper.ICustomQueryParameter AsTableValuedParameter<T>(this IEnumerable<T> enumerable,string typeName, IEnumerable<string> orderedColumnNames = null){var dataTable = new DataTable();if (typeof(T).IsValueType || typeof(T).FullName.Equals("System.String")){dataTable.Columns.Add(orderedColumnNames == null ?"NONAME" : orderedColumnNames.First(), typeof(T));foreach (T obj in enumerable){dataTable.Rows.Add(obj);}}else{PropertyInfo[] properties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);PropertyInfo[] readableProperties = properties.Where(w => w.CanRead).ToArray();if (readableProperties.Length > 1 && orderedColumnNames == null)throw new ArgumentException("Ordered list of column names must be provided when TVP contains more than one column");var columnNames = (orderedColumnNames ??readableProperties.Select(s => s.Name)).ToArray();foreach (string name in columnNames){dataTable.Columns.Add(name, readableProperties.Single(s => s.Name.Equals(name)).PropertyType);}foreach (T obj in enumerable){dataTable.Rows.Add(columnNames.Select(s => readableProperties.Single(s2 => s2.Name.Equals(s)).GetValue(obj)).ToArray());}}return dataTable.AsTableValuedParameter(typeName);}}
}

Interface for Repository

 using Dapper;
using Microsoft.Data.SqlClient;
using System.Data;namespace Data.DapperRepository.Interfaces
{public interface IDbRepository{Task<List<UserDto>> GetUsersByIdsAsync(List<int> userIds);bool AddAuditTrailLog(AbpAuditLogDto abpAuditLogDto);}
}

Implement class

using Dapper;
using Microsoft.Data.SqlClient;
using System.Data;
using Data.DapperRepository.Interfaces;namespace Data.DapperRepository
{public class DbRepository : IDbRepository{private readonly ISqlConnectionResolver _sqlConnectionResolver;public CorproLogRepository(ISqlConnectionResolver sqlConnectionResolver){_sqlConnectionResolver = sqlConnectionResolver ?? throw new ArgumentNullException(nameof(sqlConnectionResolver));}private SqlConnection GetReadOnlyConnection(){return _sqlConnectionResolver.GetSqlConnection(DBConnectionStrings.DbConnectionReadOnly);}private SqlConnection GetReadWriteDbConnection(){return _sqlConnectionResolver.GetSqlConnection(DBConnectionStrings.DbConnectionReadWrite);}public async Task<List<UserDto>> GetUsersByIdsAsync(List<int> userIds){List<UserDto> users = new();SqlConnection DbConnection = GetReadOnlyConnection();DbConnection.Open();Log.Debug($"GetFacilityLenderTreeNodesByFacilityId, Connection Name={DBConnectionStrings.DbConnectionReadOnly}");users = (await DbConnection.QueryAsync<UserDto>(sql: "SP_GET_USERS_BY_IDS",param: new { UserIds = userIds.AsTableValuedParameter("dbo.IdTable", new List<string>() { "Id" }) },commandType: CommandType.StoredProcedure)).ToList();DbConnection.Close();return users;}public bool AddAuditTrailLog(AbpAuditLogDto abpAuditLogDto){SqlConnection dbConnection = GetReadWriteDbConnection();dbConnection.Open();int num = 0;SqlCommand comm = new("SP_INSERT_API_AUDITTRAIL", dbConnection){CommandType = CommandType.StoredProcedure,CommandTimeout = 300};comm.Parameters.AddWithValue("@UserId", abpAuditLogDto.UserId);if (abpAuditLogDto.ExecutionTime.HasValue){comm.Parameters.AddWithValue("@ExecutionTime", abpAuditLogDto.ExecutionTime);}comm.Parameters.AddWithValue("@ExecutionDuration", abpAuditLogDto.ExecutionDuration);comm.Parameters.AddWithValue("@ServiceName", abpAuditLogDto.ServiceName);comm.Parameters.AddWithValue("@MethodName", abpAuditLogDto.MethodName);comm.Parameters.AddWithValue("@Parameters", abpAuditLogDto.Parameters);comm.Parameters.AddWithValue("@ClientIpAddress", abpAuditLogDto.ClientIpAddress);comm.Parameters.AddWithValue("@BrowserInfo", abpAuditLogDto.BrowserInfo);if (!string.IsNullOrEmpty(abpAuditLogDto.Exception)){comm.Parameters.AddWithValue("@Exception", abpAuditLogDto.Exception);}if (!string.IsNullOrEmpty(abpAuditLogDto.CustomData)){comm.Parameters.AddWithValue("@CustomData", abpAuditLogDto.CustomData);}num = comm.ExecuteNonQuery();dbConnection.Close();return num > 0;}}}

利用DI在.NET 6 API的Program.cs中注册ISqlConnectionResolver, and IDbRepository

//Register ISqlConnectionResolver, and IDbRepository
services.AddTransient<ISqlConnectionResolver, SqlConnectionResolver>();services.AddTransient<IDbRepository, DbRepository>();

Dapper常用functions。 IDapperManager and DapperManager

using Microsoft.Data.SqlClient;
using System.Data;namespace Data.Interfaces
{public interface IDapperManager{int Execute(string sqlCommand, object parameters, int? commandTimeout = null, CommandType commandType = CommandType.Text);int Execute(string sqlCommand, object parameters, CommandType commandType);List<SqlParameter> ExecuteWithOutput(string sqlCommand, object parameters, CommandType commandType);/// <summary>/// Function to invoke SQL command async with CommandType, and has Retry mode./// </summary>Task<int> ExecuteAsync(string sqlCommand, object parameters);string ExecuteNonQuery(string sqlCommand, object parameters, CommandType commandType);SqlConnection GetSqlConnection();List<int> QueryEntities(string sqlCommand, object parameters);List<int> QueryEntities(string sqlCommand, object parameters, CommandType commandType);List<T> QueryEntities<T>(string sqlCommand, object parameters);List<T> QueryEntities<T>(string sqlCommand, object parameters, CommandType commandType);List<T6> QueryEntities<T1, T2, T3, T4, T5, T6>(string sqlCommand, object parameters, Func<T1, T2, T3, T4, T5, T6> mapLogic, string splitOn, CommandType commandType);List<T5> QueryEntities<T1, T2, T3, T4, T5>(string sqlCommand, object parameters, Func<T1, T2, T3, T4, T5> mapLogic, string splitOn);List<T5> QueryEntities<T1, T2, T3, T4, T5>(string sqlCommand, object parameters, Func<T1, T2, T3, T4, T5> mapLogic, string splitOn, CommandType commandType);List<T4> QueryEntities<T1, T2, T3, T4>(string sqlCommand, object parameters, Func<T1, T2, T3, T4> mapLogic, string splitOn);List<T4> QueryEntities<T1, T2, T3, T4>(string sqlCommand, object parameters, Func<T1, T2, T3, T4> mapLogic, string splitOn, CommandType commandType);List<T3> QueryEntities<T1, T2, T3>(string sqlCommand, object parameters, Func<T1, T2, T3> mapLogic, string splitOn, CommandType commandType = CommandType.Text);Task<List<T>> QueryEntitiesAsync<T>(string sqlCommand, object parameters) where T : class, new();Tuple<List<T1>, List<T2>, List<T3>> QueryMultiEntities<T1, T2, T3>(string sqlCommand, object parameters, CommandType commandType = CommandType.StoredProcedure);Tuple<List<T1>, List<T2>> QueryMultiEntities<T1, T2>(string sqlCommand, object parameters, CommandType commandType = CommandType.StoredProcedure);}
}
using Dapper;
using Microsoft.Data.SqlClient;
using Serilog;
using System.Data;
using static Dapper.SqlMapper;
using System.Data;
using Data.Interfaces;namespace Data.Managers
{public class DapperManager : IDapperManager{#region Membersprivate string _connectionString { get; set; }#endregion#region Ctorspublic DapperManager(string connectionString){_connectionString = connectionString;}#endregion#region Functionspublic List<int> QueryEntities(string sqlCommand, object parameters, CommandType commandType){using (SqlConnection Connection = GetSqlConnection()){try{Connection.Open();List<int> returnValues = Connection.Query<int>(sqlCommand, parameters, commandType: commandType).ToList();Connection.Close();Connection.Dispose();return returnValues;}catch (Exception e){Log.Error(e.Message, e);}finally{Connection.Close();Connection.Dispose();}}return new List<int>();}public List<int> QueryEntities(string sqlCommand, object parameters){return QueryEntities(sqlCommand, parameters, CommandType.Text);}public List<T> QueryEntities<T>(string sqlCommand, object parameters, CommandType commandType){using (SqlConnection Connection = GetSqlConnection()){try{Connection.Open();List<T> returnValues = Connection.Query<T>(sqlCommand, parameters, commandType: commandType).ToList();Connection.Close();Connection.Dispose();return returnValues;}catch (Exception e){Log.Error(e.Message, e);throw;}finally{Connection.Close();Connection.Dispose();}}}public List<T> QueryEntities<T>(string sqlCommand, object parameters){return QueryEntities<T>(sqlCommand, parameters, CommandType.Text);}public async Task<List<T>> QueryEntitiesAsync<T>(string sqlCommand, object parameters) where T : class, new(){using (SqlConnection Connection = GetSqlConnection()){try{Connection.Open();var returnValues = Connection.QueryAsync<T>(sqlCommand, parameters);await returnValues;Connection.Close();Connection.Dispose();return returnValues.Result.ToList();}catch (Exception e){Log.Error(e.Message, e);}finally{Connection.Close();Connection.Dispose();}}return new List<T>();}public List<T3> QueryEntities<T1, T2, T3>(string sqlCommand, object parameters, Func<T1, T2, T3> mapLogic, string splitOn, CommandType commandType = CommandType.Text){using (SqlConnection Connection = GetSqlConnection()){try{Connection.Open();List<T3> returnValues = Connection.Query(sqlCommand, mapLogic, parameters, commandType: commandType, splitOn: splitOn).ToList();Connection.Close();Connection.Dispose();return returnValues;}catch (Exception e){Log.Error(e.Message, e);}finally{Connection.Close();Connection.Dispose();}}return new List<T3>();}public List<T4> QueryEntities<T1, T2, T3, T4>(string sqlCommand, object parameters, Func<T1, T2, T3, T4> mapLogic, string splitOn){return QueryEntities(sqlCommand, parameters, mapLogic, splitOn, CommandType.Text);}public List<T4> QueryEntities<T1, T2, T3, T4>(string sqlCommand, object parameters, Func<T1, T2, T3, T4> mapLogic, string splitOn, CommandType commandType){using (SqlConnection Connection = GetSqlConnection()){try{Connection.Open();List<T4> returnValues = Connection.Query(sqlCommand, mapLogic, parameters, splitOn: splitOn, commandType: commandType).ToList();Connection.Close();Connection.Dispose();return returnValues;}catch (Exception e){Log.Error(e.Message, e);}finally{Connection.Close();Connection.Dispose();}}return new List<T4>();}public List<T5> QueryEntities<T1, T2, T3, T4, T5>(string sqlCommand, object parameters, Func<T1, T2, T3, T4, T5> mapLogic, string splitOn, CommandType commandType){using (SqlConnection Connection = GetSqlConnection()){try{Connection.Open();List<T5> returnValues = Connection.Query(sqlCommand, mapLogic, parameters, splitOn: splitOn, commandType: commandType).ToList();Connection.Close();Connection.Dispose();return returnValues;}catch (Exception e){Log.Error(e.Message, e);}finally{Connection.Close();Connection.Dispose();}}return new List<T5>();}public List<T5> QueryEntities<T1, T2, T3, T4, T5>(string sqlCommand, object parameters, Func<T1, T2, T3, T4, T5> mapLogic, string splitOn){return QueryEntities(sqlCommand, parameters, mapLogic, splitOn, CommandType.Text);}public List<T6> QueryEntities<T1, T2, T3, T4, T5, T6>(string sqlCommand, object parameters, Func<T1, T2, T3, T4, T5, T6> mapLogic, string splitOn, CommandType commandType){using (SqlConnection Connection = GetSqlConnection()){try{Connection.Open();List<T6> returnValues = Connection.Query(sqlCommand, mapLogic, parameters, splitOn: splitOn, commandType: commandType).ToList();Connection.Close();Connection.Dispose();return returnValues;}catch (Exception e){Log.Error(e.Message, e);}finally{Connection.Close();Connection.Dispose();}}return new List<T6>();}public int Execute(string sqlCommand, object parameters, int? commandTimeout = null, CommandType commandType = CommandType.Text){using (SqlConnection Connection = GetSqlConnection()){try{Connection.Open();int returnValues = Connection.Execute(sqlCommand, parameters, commandTimeout: commandTimeout, commandType: commandType);Connection.Close();Connection.Dispose();return returnValues;}catch (Exception e){Log.Error(e.Message, e);}finally{Connection.Close();Connection.Dispose();}}return -1;  // Failure.}public int Execute(string sqlCommand, object parameters, CommandType commandType){using (SqlConnection connection = GetSqlConnection())using (SqlCommand command = connection.CreateCommand()){try{command.CommandText = sqlCommand;command.CommandType = commandType;if (parameters != null){foreach (var p in (List<SqlParameter>)parameters){command.Parameters.Add(p);}}connection.Open();int result = command.ExecuteNonQuery();if (parameters != null && parameters is List<SqlParameter>){SqlParameter sqlParameter = ((List<SqlParameter>)parameters).Last();if (sqlParameter != null && (sqlParameter.Direction == ParameterDirection.ReturnValue || sqlParameter.Direction == ParameterDirection.Output) && sqlParameter.SqlDbType == SqlDbType.Int){result = (int)((List<SqlParameter>)parameters).Last().Value;}}return result;}finally{connection.Close();connection.Dispose();}}}public List<SqlParameter> ExecuteWithOutput(string sqlCommand, object parameters, CommandType commandType){using (SqlConnection connection = GetSqlConnection())using (SqlCommand command = connection.CreateCommand()){try{command.CommandText = sqlCommand;command.CommandType = commandType;if (parameters != null){foreach (var p in (List<SqlParameter>)parameters){command.Parameters.Add(p);}}connection.Open();int result = command.ExecuteNonQuery();if (parameters != null && parameters is List<SqlParameter>){var sqlParameters = (List<SqlParameter>)parameters;return sqlParameters.Where(x => x.Direction == ParameterDirection.Output).ToList();}}catch (Exception ex){Log.Error(ex.Message, ex);}finally{connection.Close();connection.Dispose();}}return null;}public async Task<int> ExecuteAsync(string sqlCommand, object parameters){using (SqlConnection Connection = GetSqlConnection()){try{Connection.Open();int returnValues = await Connection.ExecuteAsync(sqlCommand, parameters, commandType: CommandType.StoredProcedure);Connection.Close();Connection.Dispose();return returnValues;}catch (Exception e){Log.Error(e.Message, e);}finally{Connection.Close();Connection.Dispose();}}return 0;}/// <summary>/// Function to ExecuteNonQuery and return messages for this sqlCommand result./// </summary>public string ExecuteNonQuery(string sqlCommand, object parameters, CommandType commandType){var messages = string.Empty;using (var connection = GetSqlConnection())using (var command = connection.CreateCommand()){try{connection.Open();command.CommandText = sqlCommand;command.CommandType = commandType;if (parameters != null){foreach (var p in (List<SqlParameter>)parameters){command.Parameters.Add(p);}}connection.FireInfoMessageEventOnUserErrors = true;connection.InfoMessage += (sender, args) =>{messages += "\r\n" + args.Message;};command.ExecuteNonQuery();}catch (Exception e){Log.Error(e.Message, e);messages += "\r\n" + e.Message;}finally{connection.Close();}}return messages;}public Tuple<List<T1>, List<T2>> QueryMultiEntities<T1, T2>(string sqlCommand, object parameters, CommandType commandType = CommandType.StoredProcedure){using (SqlConnection Connection = GetSqlConnection()){try{Connection.Open();var reader = Connection.QueryMultiple(sqlCommand, parameters, commandType: commandType);List<T1> list1 = new List<T1>();List<T2> list2 = new List<T2>();if (reader != null){list1 = reader?.Read<T1>()?.ToList();list2 = reader?.Read<T2>()?.ToList();}Connection.Close();Connection.Dispose();return Tuple.Create(list1, list2);}catch (Exception e){Log.Error(e.Message, e);}finally{Connection.Close();Connection.Dispose();}}return null;}public Tuple<List<T1>, List<T2>, List<T3>> QueryMultiEntities<T1, T2, T3>(string sqlCommand, object parameters, CommandType commandType = CommandType.StoredProcedure){using (SqlConnection Connection = new SqlConnection()){try{Connection.Open();GridReader reader = Connection.QueryMultiple(sqlCommand, parameters, commandType: commandType);List<T1> list1 = new List<T1>();List<T2> list2 = new List<T2>();List<T3> list3 = new List<T3>();if (reader != null){IEnumerable<T1> en1 = reader.Read<T1>();IEnumerable<T2> en2 = reader.Read<T2>();list3 = reader.Read<T3>().ToList();if (en1 != null){list1 = en1.ToList();}if (en2 != null){list2 = en2.ToList();}}Connection.Close();Connection.Dispose();return Tuple.Create(list1, list2, list3);}catch (Exception e){Log.Error(e.Message, e);}finally{Connection.Close();Connection.Dispose();}}return null;}#endregion#region Help Functionpublic SqlConnection GetSqlConnection(){return new SqlConnection(_connectionString);}#endregion}
}

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

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

C++ day03

思维导图 头文件 #ifndef SEQLIST_H #define SEQLIST_Husing datatype int;class seqlist { private:datatype *ptr; // 动态数组指针int size; // 顺序表最大容量int len 0; // 当前长度public:void init(int n); // 初始化顺序表bool empty(); …

RflySim工具链常见问题答疑

1. RflySim结合硬件能不能实现无人机颜色巡线呢&#xff1f; 可以&#xff0c;内置有一个通过相机识别来攻击小球的实验&#xff0c;可见&#xff1a;【RflySim安装路径】\RflySimAPIs\8.RflySimVision\1.BasicExps\1-VisionCtrlDemos\e3_ShootBall&#xff0c;不过要想实现无人…

elasticsearch同步mysql方案

文章目录 1、1. 使用数据库触发器2. 使用定时任务3. 监听MySQL二进制日志&#xff08;binlog&#xff09;4. 使用数据管道5. 使用第三方工具或服务6. 编写自定义脚本注意事项 2、1. 使用Logstash步骤&#xff1a;示例配置&#xff1a; 2. 使用Debezium步骤&#xff1a; 3. 自定…

ES6标准---【九】【学习ES6标准看这一篇就够了!!!】

目录 以往ES6文章 JavaScript在浏览器中的加载 传统方法 加载规则 注意 顶部变量外部不可用 this关键字返回undefined JavaScript的循环加载 ES6模块的循环加载 块级作用域 let取代var 全局变量和线程安全 以往ES6文章 ES6标准---【一】【学习ES6看这一篇就够了&…

小小扑克牌算法

1.定义一个扑克牌类Card&#xff1a; package democard; public class Card {public String suit;//表示花色public int rank;//表示牌点数Overridepublic String toString() {return "{"suit rank"}";}//实例方法&#xff0c;初始化牌的点数和花色public…

【Redis入门到精通三】Redis核心数据类型(List,Set)详解

目录 Redis数据类型 ​编辑 1.List类型 &#xff08;1&#xff09;常见命令 &#xff08;2&#xff09;内部编码 2.Set类型 &#xff08;1&#xff09;常见命令 &#xff08;2&#xff09;内部编码 Redis数据类型 查阅Redis官方文档可知&#xff0c;Redis提供给用户的核…

【类型黑市】指针

大家好我是#Y清墨&#xff0c;今天我要介绍的是指针。 意义 指针就是存放内存地址的变量。 分类 因为变量本身是分类型的&#xff0c;我们学过的变量类型有 int, long long, char, double, string, 甚至还有结构体变量。 同样&#xff0c;指针也分类型&#xff0c;如果指针指向…

完美转发、C++11中与线程相关的std::ref

目录 模板中的万能引用 std::forward实现完美转发 C11中与线程相关的std::ref 线程函数参数 用函数指针作为线程函数 用lambda表达式作为线程函数 模板中的万能引用 void Func(int& x) {cout << "左值引用" << endl; } void Func(int&&am…

3. Internet 协议的安全性

3. Internet 协议的安全性 (1) 常用网络协议的功能、使用的端口及安全性 HTTP协议 功能:用于从服务器传输超文本到本地浏览器。端口:默认是80端口。安全性:不提供数据加密,存在数据泄露和中间人攻击风险。使用HTTPS协议(443端口)可以增强安全性。FTP协议 功能:实现文件的…

IPv6(四)

文章目录 Path MTUIPv6配置 Path MTU IPv4 对于数据过大的数据包会执行切片操作&#xff0c;但是切片有可能会造成设备性能的降低 IPv6使用Path MTU来传递数据过大的数据包 依次会协商最小的 MTU 单元为了减少中间转发设备的压力&#xff0c;中间转发设备不对 IPv6 报文进行分片…

re题(36)BUUCTF-[WUSTCTF2020]Cr0ssfun

BUUCTF在线评测 (buuoj.cn) 查一下壳&#xff0c;64位elf文件 ctrle找到main()函数 只进行了一个比较函数&#xff0c;看一下check() 猜测是a1中存放的flag&#xff0c;往下继续查看函数 把a1中存的数据都给出来了 写个脚本&#xff0c;输出一下a1&#xff0c;直接就是我们要的…

Python 找到给定点集的简单闭合路径(Find Simple Closed Path for a given set of points)

给定一组点&#xff0c;将这些点连接起来而不相交 例子&#xff1a; 输入&#xff1a;points[] {(0, 3), (1, 1), (2, 2), (4, 4), (0, 0), (1, 2), (3, 1}, {3, 3}}; 输出&#xff1a;按以下顺序连接点将 不造成任何交叉 {(0, 0), (3, …

CSS - 通用左边图片,右边内容,并且控制长度溢出处理模板(vue | uniapp | 微信小程序)

前言 通用模板&#xff0c;可适用于任意前端项目。 如下图所示&#xff0c;手机电脑通用。 示例代码 根据自己的需求修改即可。 <body><div class"container"><!-- 头像图片 --><img class"avatar" src"https://cdn.uviewui.com…

OpenSSH从7.4升级到9.8的过程 亲测--图文详解

一、下载软件 下载openssh 下载地址&#xff1a; Downloads | Library 下载openssl Index of /pub/OpenBSD/OpenSSH/ zlib Home Site 安装的 openssl-3.3.1.tar.gz ,安装3.3.2有问题 安装有问题&#xff0c; 二、安装依赖 yum install -y perl-CPAN perl-ExtUtils-CB…

手动部署并测试内网穿透

文章目录 手动部署并测试内网穿透1、原理2、下载 frp 文件3、配置对应的配置文件4、启动 frp 服务5、效果 手动部署并测试内网穿透 1、原理 原理就是让你需要访问的内网可以被其他内网访问到。 其实就是让内网经过一个公网服务器的转发&#xff0c;使得能够被访问。 这里我们需…

【Python报错已解决】ModuleNotFoundError: No module named ‘tensorflow‘

&#x1f3ac; 鸽芷咕&#xff1a;个人主页 &#x1f525; 个人专栏: 《C干货基地》《粉丝福利》 ⛺️生活的理想&#xff0c;就是为了理想的生活! 专栏介绍 在软件开发和日常使用中&#xff0c;BUG是不可避免的。本专栏致力于为广大开发者和技术爱好者提供一个关于BUG解决的经…

物联网开发+充电桩管理系统+充电桩系统源码

简述 SpringBoot 框架&#xff0c;充电桩平台充电桩系统充电平台充电桩互联互通协议云快充协议1.5新能源汽车电动自行车公交车-四轮车充电充电源代码充电平台源码Java源码无加密项目 介绍 云快充协议云快充1.5协议云快充协议开源代码云快充底层协议云快充桩直连桩直连协议充…

半导体器件制造5G智能工厂数字孪生物联平台,推进制造业数字化转型

半导体器件制造行业作为高科技领域的核心驱动力&#xff0c;正积极探索和实践以5G智能工厂数字孪生平台为核心的新型制造模式。这一创新不仅极大地提升了生产效率与质量&#xff0c;更为制造业的未来发展绘制了一幅智能化、网络化的宏伟蓝图。 在半导体器件制造5G智能工厂中&a…

每天五分钟计算机视觉:将人脸识别问题转换为二分类问题

本文重点 在前面的课程中,我们学习了两种人脸识别的网络模型,这两种人脸识别网络不能算是基于距离或者Triplet loss等等完成的神经网络参数的学习。我们比较熟悉的是分类任务,那么人脸识别是否可以转变为分类任务呢? 本节课程我们将介绍一种全新的方法来学习神经网络的参…

微服务架构陷阱与挑战

微服务架构6大陷阱 现在微服务的基础设施还是越来越完善了&#xff0c;现在基础设施缺乏的问题逐渐被解决了。 拆分粒度太细&#xff0c;服务关系复杂 拆分降低了服务的内部复杂度&#xff0c;但是提升了系统的外部复杂度&#xff0c;服务越多&#xff0c;服务和服务之间的连接…