.NET生成MongoDB中的主键ObjectId
前言
因为很多场景下我们需要在创建MongoDB数据的时候提前生成好主键为了返回或者通过主键查询创建的业务,像EF中我们可以生成Guid来,本来想着要不要实现一套MongoDB中ObjectId的,结果发现网上各种各样的实现都有,不过好在阅读C#MongoDB驱动mongo-csharp-driver代码的时候发现有ObjectId.GenerateNewId()的方法提供,我们可以直接调用即可,不需要我们在花费多余的时间设计重写了。
MongoDB ObjectId类型概述
每次插入一条数据系统都会自动插入一个_id键,键值不可以重复,它可以是任何类型的,也可以手动的插入,默认情况下它的数据类型是ObjectId,由于MongoDB在设计之初就是用作分布式数据库,所以使用ObjectId可以避免不同数据库中_id的重复(如果使用自增的方式在分布式系统中就会出现重复的_id的值)。
ObjectId使用12字节的存储空间,每个字节可以存储两个十六进制数字,所以一共可以存储24个十六进制数字组成的字符串,在这24个字符串中,前8位表示时间戳,接下来6位是一个机器码,接下来4位表示进程id,最后6位表示计数器。
MongoDB 采用 ObjectId 来表示主键的类型,数据库中每个文档都拥有一个_id 字段表示主键,_id 的生成规则如下:
其中包括:4-byte Unix 时间戳,3-byte 机器 ID,2-byte 进程 ID,3-byte 计数器(初始化随机)。

601e2b6b a3203c c89f 2d31aa↑ ↑ ↑ ↑时间戳 机器码 进程ID 随机数
MongoDB.Driver驱动安装
1、直接命令自动安装
Install-Package MongoDB.Driver
2、搜索Nuget手动安装

调用生成主键ObjectId
var primarykeyId = ObjectId.GenerateNewId();
//输出:641c54b2e674000035001dc2
mongo-csharp-driver ObjectId详解
关于ObjectId的生成原理大家阅读如下源码即可。
源码地址:https://github.com/mongodb/mongo-csharp-driver/blob/ec74978f7e827515f29cc96fba0c727828e8df7c/src/MongoDB.Bson/ObjectModel/ObjectId.cs
/* Copyright 2010-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Security;
using System.Threading;namespace MongoDB.Bson
{/// <summary>/// Represents an ObjectId (see also BsonObjectId)./// </summary>
#if NET45[Serializable]
#endifpublic struct ObjectId : IComparable<ObjectId>, IEquatable<ObjectId>, IConvertible{// private static fieldsprivate static readonly ObjectId __emptyInstance = default(ObjectId);private static readonly int __staticMachine = (GetMachineHash() + GetAppDomainId()) & 0x00ffffff;private static readonly short __staticPid = GetPid();private static int __staticIncrement = (new Random()).Next();// private fieldsprivate readonly int _a;private readonly int _b;private readonly int _c;// constructors/// <summary>/// Initializes a new instance of the ObjectId class./// </summary>/// <param name="bytes">The bytes.</param>public ObjectId(byte[] bytes){if (bytes == null){throw new ArgumentNullException("bytes");}if (bytes.Length != 12){throw new ArgumentException("Byte array must be 12 bytes long", "bytes");}FromByteArray(bytes, 0, out _a, out _b, out _c);}/// <summary>/// Initializes a new instance of the ObjectId class./// </summary>/// <param name="bytes">The bytes.</param>/// <param name="index">The index into the byte array where the ObjectId starts.</param>internal ObjectId(byte[] bytes, int index){FromByteArray(bytes, index, out _a, out _b, out _c);}/// <summary>/// Initializes a new instance of the ObjectId class./// </summary>/// <param name="timestamp">The timestamp (expressed as a DateTime).</param>/// <param name="machine">The machine hash.</param>/// <param name="pid">The PID.</param>/// <param name="increment">The increment.</param>public ObjectId(DateTime timestamp, int machine, short pid, int increment): this(GetTimestampFromDateTime(timestamp), machine, pid, increment){}/// <summary>/// Initializes a new instance of the ObjectId class./// </summary>/// <param name="timestamp">The timestamp.</param>/// <param name="machine">The machine hash.</param>/// <param name="pid">The PID.</param>/// <param name="increment">The increment.</param>public ObjectId(int timestamp, int machine, short pid, int increment){if ((machine & 0xff000000) != 0){throw new ArgumentOutOfRangeException("machine", "The machine value must be between 0 and 16777215 (it must fit in 3 bytes).");}if ((increment & 0xff000000) != 0){throw new ArgumentOutOfRangeException("increment", "The increment value must be between 0 and 16777215 (it must fit in 3 bytes).");}_a = timestamp;_b = (machine << 8) | (((int)pid >> 8) & 0xff);_c = ((int)pid << 24) | increment;}/// <summary>/// Initializes a new instance of the ObjectId class./// </summary>/// <param name="value">The value.</param>public ObjectId(string value){if (value == null){throw new ArgumentNullException("value");}var bytes = BsonUtils.ParseHexString(value);FromByteArray(bytes, 0, out _a, out _b, out _c);}// public static properties/// <summary>/// Gets an instance of ObjectId where the value is empty./// </summary>public static ObjectId Empty{get { return __emptyInstance; }}// public properties/// <summary>/// Gets the timestamp./// </summary>public int Timestamp{get { return _a; }}/// <summary>/// Gets the machine./// </summary>public int Machine{get { return (_b >> 8) & 0xffffff; }}/// <summary>/// Gets the PID./// </summary>public short Pid{get { return (short)(((_b << 8) & 0xff00) | ((_c >> 24) & 0x00ff)); }}/// <summary>/// Gets the increment./// </summary>public int Increment{get { return _c & 0xffffff; }}/// <summary>/// Gets the creation time (derived from the timestamp)./// </summary>public DateTime CreationTime{get { return BsonConstants.UnixEpoch.AddSeconds(Timestamp); }}// public operators/// <summary>/// Compares two ObjectIds./// </summary>/// <param name="lhs">The first ObjectId.</param>/// <param name="rhs">The other ObjectId</param>/// <returns>True if the first ObjectId is less than the second ObjectId.</returns>public static bool operator <(ObjectId lhs, ObjectId rhs){return lhs.CompareTo(rhs) < 0;}/// <summary>/// Compares two ObjectIds./// </summary>/// <param name="lhs">The first ObjectId.</param>/// <param name="rhs">The other ObjectId</param>/// <returns>True if the first ObjectId is less than or equal to the second ObjectId.</returns>public static bool operator <=(ObjectId lhs, ObjectId rhs){return lhs.CompareTo(rhs) <= 0;}/// <summary>/// Compares two ObjectIds./// </summary>/// <param name="lhs">The first ObjectId.</param>/// <param name="rhs">The other ObjectId.</param>/// <returns>True if the two ObjectIds are equal.</returns>public static bool operator ==(ObjectId lhs, ObjectId rhs){return lhs.Equals(rhs);}/// <summary>/// Compares two ObjectIds./// </summary>/// <param name="lhs">The first ObjectId.</param>/// <param name="rhs">The other ObjectId.</param>/// <returns>True if the two ObjectIds are not equal.</returns>public static bool operator !=(ObjectId lhs, ObjectId rhs){return !(lhs == rhs);}/// <summary>/// Compares two ObjectIds./// </summary>/// <param name="lhs">The first ObjectId.</param>/// <param name="rhs">The other ObjectId</param>/// <returns>True if the first ObjectId is greather than or equal to the second ObjectId.</returns>public static bool operator >=(ObjectId lhs, ObjectId rhs){return lhs.CompareTo(rhs) >= 0;}/// <summary>/// Compares two ObjectIds./// </summary>/// <param name="lhs">The first ObjectId.</param>/// <param name="rhs">The other ObjectId</param>/// <returns>True if the first ObjectId is greather than the second ObjectId.</returns>public static bool operator >(ObjectId lhs, ObjectId rhs){return lhs.CompareTo(rhs) > 0;}// public static methods/// <summary>/// Generates a new ObjectId with a unique value./// </summary>/// <returns>An ObjectId.</returns>public static ObjectId GenerateNewId(){return GenerateNewId(GetTimestampFromDateTime(DateTime.UtcNow));}/// <summary>/// Generates a new ObjectId with a unique value (with the timestamp component based on a given DateTime)./// </summary>/// <param name="timestamp">The timestamp component (expressed as a DateTime).</param>/// <returns>An ObjectId.</returns>public static ObjectId GenerateNewId(DateTime timestamp){return GenerateNewId(GetTimestampFromDateTime(timestamp));}/// <summary>/// Generates a new ObjectId with a unique value (with the given timestamp)./// </summary>/// <param name="timestamp">The timestamp component.</param>/// <returns>An ObjectId.</returns>public static ObjectId GenerateNewId(int timestamp){int increment = Interlocked.Increment(ref __staticIncrement) & 0x00ffffff; // only use low order 3 bytesreturn new ObjectId(timestamp, __staticMachine, __staticPid, increment);}/// <summary>/// Packs the components of an ObjectId into a byte array./// </summary>/// <param name="timestamp">The timestamp.</param>/// <param name="machine">The machine hash.</param>/// <param name="pid">The PID.</param>/// <param name="increment">The increment.</param>/// <returns>A byte array.</returns>public static byte[] Pack(int timestamp, int machine, short pid, int increment){if ((machine & 0xff000000) != 0){throw new ArgumentOutOfRangeException("machine", "The machine value must be between 0 and 16777215 (it must fit in 3 bytes).");}if ((increment & 0xff000000) != 0){throw new ArgumentOutOfRangeException("increment", "The increment value must be between 0 and 16777215 (it must fit in 3 bytes).");}byte[] bytes = new byte[12];bytes[0] = (byte)(timestamp >> 24);bytes[1] = (byte)(timestamp >> 16);bytes[2] = (byte)(timestamp >> 8);bytes[3] = (byte)(timestamp);bytes[4] = (byte)(machine >> 16);bytes[5] = (byte)(machine >> 8);bytes[6] = (byte)(machine);bytes[7] = (byte)(pid >> 8);bytes[8] = (byte)(pid);bytes[9] = (byte)(increment >> 16);bytes[10] = (byte)(increment >> 8);bytes[11] = (byte)(increment);return bytes;}/// <summary>/// Parses a string and creates a new ObjectId./// </summary>/// <param name="s">The string value.</param>/// <returns>A ObjectId.</returns>public static ObjectId Parse(string s){if (s == null){throw new ArgumentNullException("s");}ObjectId objectId;if (TryParse(s, out objectId)){return objectId;}else{var message = string.Format("'{0}' is not a valid 24 digit hex string.", s);throw new FormatException(message);}}/// <summary>/// Tries to parse a string and create a new ObjectId./// </summary>/// <param name="s">The string value.</param>/// <param name="objectId">The new ObjectId.</param>/// <returns>True if the string was parsed successfully.</returns>public static bool TryParse(string s, out ObjectId objectId){// don't throw ArgumentNullException if s is nullif (s != null && s.Length == 24){byte[] bytes;if (BsonUtils.TryParseHexString(s, out bytes)){objectId = new ObjectId(bytes);return true;}}objectId = default(ObjectId);return false;}/// <summary>/// Unpacks a byte array into the components of an ObjectId./// </summary>/// <param name="bytes">A byte array.</param>/// <param name="timestamp">The timestamp.</param>/// <param name="machine">The machine hash.</param>/// <param name="pid">The PID.</param>/// <param name="increment">The increment.</param>public static void Unpack(byte[] bytes, out int timestamp, out int machine, out short pid, out int increment){if (bytes == null){throw new ArgumentNullException("bytes");}if (bytes.Length != 12){throw new ArgumentOutOfRangeException("bytes", "Byte array must be 12 bytes long.");}timestamp = (bytes[0] << 24) + (bytes[1] << 16) + (bytes[2] << 8) + bytes[3];machine = (bytes[4] << 16) + (bytes[5] << 8) + bytes[6];pid = (short)((bytes[7] << 8) + bytes[8]);increment = (bytes[9] << 16) + (bytes[10] << 8) + bytes[11];}// private static methodsprivate static int GetAppDomainId(){
#if NETSTANDARD1_5 || NETSTANDARD1_6return 1;
#elsereturn AppDomain.CurrentDomain.Id;
#endif}/// <summary>/// Gets the current process id. This method exists because of how CAS operates on the call stack, checking/// for permissions before executing the method. Hence, if we inlined this call, the calling method would not execute/// before throwing an exception requiring the try/catch at an even higher level that we don't necessarily control./// </summary>[MethodImpl(MethodImplOptions.NoInlining)]private static int GetCurrentProcessId(){return Process.GetCurrentProcess().Id;}private static int GetMachineHash(){// use instead of Dns.HostName so it will work offlinevar machineName = GetMachineName();return 0x00ffffff & machineName.GetHashCode(); // use first 3 bytes of hash}private static string GetMachineName(){return Environment.MachineName;}private static short GetPid(){try{return (short)GetCurrentProcessId(); // use low order two bytes only}catch (SecurityException){return 0;}}private static int GetTimestampFromDateTime(DateTime timestamp){var secondsSinceEpoch = (long)Math.Floor((BsonUtils.ToUniversalTime(timestamp) - BsonConstants.UnixEpoch).TotalSeconds);if (secondsSinceEpoch < int.MinValue || secondsSinceEpoch > int.MaxValue){throw new ArgumentOutOfRangeException("timestamp");}return (int)secondsSinceEpoch;}private static void FromByteArray(byte[] bytes, int offset, out int a, out int b, out int c){a = (bytes[offset] << 24) | (bytes[offset + 1] << 16) | (bytes[offset + 2] << 8) | bytes[offset + 3];b = (bytes[offset + 4] << 24) | (bytes[offset + 5] << 16) | (bytes[offset + 6] << 8) | bytes[offset + 7];c = (bytes[offset + 8] << 24) | (bytes[offset + 9] << 16) | (bytes[offset + 10] << 8) | bytes[offset + 11];}// public methods/// <summary>/// Compares this ObjectId to another ObjectId./// </summary>/// <param name="other">The other ObjectId.</param>/// <returns>A 32-bit signed integer that indicates whether this ObjectId is less than, equal to, or greather than the other.</returns>public int CompareTo(ObjectId other){int result = ((uint)_a).CompareTo((uint)other._a);if (result != 0) { return result; }result = ((uint)_b).CompareTo((uint)other._b);if (result != 0) { return result; }return ((uint)_c).CompareTo((uint)other._c);}/// <summary>/// Compares this ObjectId to another ObjectId./// </summary>/// <param name="rhs">The other ObjectId.</param>/// <returns>True if the two ObjectIds are equal.</returns>public bool Equals(ObjectId rhs){return_a == rhs._a &&_b == rhs._b &&_c == rhs._c;}/// <summary>/// Compares this ObjectId to another object./// </summary>/// <param name="obj">The other object.</param>/// <returns>True if the other object is an ObjectId and equal to this one.</returns>public override bool Equals(object obj){if (obj is ObjectId){return Equals((ObjectId)obj);}else{return false;}}/// <summary>/// Gets the hash code./// </summary>/// <returns>The hash code.</returns>public override int GetHashCode(){int hash = 17;hash = 37 * hash + _a.GetHashCode();hash = 37 * hash + _b.GetHashCode();hash = 37 * hash + _c.GetHashCode();return hash;}/// <summary>/// Converts the ObjectId to a byte array./// </summary>/// <returns>A byte array.</returns>public byte[] ToByteArray(){var bytes = new byte[12];ToByteArray(bytes, 0);return bytes;}/// <summary>/// Converts the ObjectId to a byte array./// </summary>/// <param name="destination">The destination.</param>/// <param name="offset">The offset.</param>public void ToByteArray(byte[] destination, int offset){if (destination == null){throw new ArgumentNullException("destination");}if (offset + 12 > destination.Length){throw new ArgumentException("Not enough room in destination buffer.", "offset");}destination[offset + 0] = (byte)(_a >> 24);destination[offset + 1] = (byte)(_a >> 16);destination[offset + 2] = (byte)(_a >> 8);destination[offset + 3] = (byte)(_a);destination[offset + 4] = (byte)(_b >> 24);destination[offset + 5] = (byte)(_b >> 16);destination[offset + 6] = (byte)(_b >> 8);destination[offset + 7] = (byte)(_b);destination[offset + 8] = (byte)(_c >> 24);destination[offset + 9] = (byte)(_c >> 16);destination[offset + 10] = (byte)(_c >> 8);destination[offset + 11] = (byte)(_c);}/// <summary>/// Returns a string representation of the value./// </summary>/// <returns>A string representation of the value.</returns>public override string ToString(){var c = new char[24];c[0] = BsonUtils.ToHexChar((_a >> 28) & 0x0f);c[1] = BsonUtils.ToHexChar((_a >> 24) & 0x0f);c[2] = BsonUtils.ToHexChar((_a >> 20) & 0x0f);c[3] = BsonUtils.ToHexChar((_a >> 16) & 0x0f);c[4] = BsonUtils.ToHexChar((_a >> 12) & 0x0f);c[5] = BsonUtils.ToHexChar((_a >> 8) & 0x0f);c[6] = BsonUtils.ToHexChar((_a >> 4) & 0x0f);c[7] = BsonUtils.ToHexChar(_a & 0x0f);c[8] = BsonUtils.ToHexChar((_b >> 28) & 0x0f);c[9] = BsonUtils.ToHexChar((_b >> 24) & 0x0f);c[10] = BsonUtils.ToHexChar((_b >> 20) & 0x0f);c[11] = BsonUtils.ToHexChar((_b >> 16) & 0x0f);c[12] = BsonUtils.ToHexChar((_b >> 12) & 0x0f);c[13] = BsonUtils.ToHexChar((_b >> 8) & 0x0f);c[14] = BsonUtils.ToHexChar((_b >> 4) & 0x0f);c[15] = BsonUtils.ToHexChar(_b & 0x0f);c[16] = BsonUtils.ToHexChar((_c >> 28) & 0x0f);c[17] = BsonUtils.ToHexChar((_c >> 24) & 0x0f);c[18] = BsonUtils.ToHexChar((_c >> 20) & 0x0f);c[19] = BsonUtils.ToHexChar((_c >> 16) & 0x0f);c[20] = BsonUtils.ToHexChar((_c >> 12) & 0x0f);c[21] = BsonUtils.ToHexChar((_c >> 8) & 0x0f);c[22] = BsonUtils.ToHexChar((_c >> 4) & 0x0f);c[23] = BsonUtils.ToHexChar(_c & 0x0f);return new string(c);}// explicit IConvertible implementationTypeCode IConvertible.GetTypeCode(){return TypeCode.Object;}bool IConvertible.ToBoolean(IFormatProvider provider){throw new InvalidCastException();}byte IConvertible.ToByte(IFormatProvider provider){throw new InvalidCastException();}char IConvertible.ToChar(IFormatProvider provider){throw new InvalidCastException();}DateTime IConvertible.ToDateTime(IFormatProvider provider){throw new InvalidCastException();}decimal IConvertible.ToDecimal(IFormatProvider provider){throw new InvalidCastException();}double IConvertible.ToDouble(IFormatProvider provider){throw new InvalidCastException();}short IConvertible.ToInt16(IFormatProvider provider){throw new InvalidCastException();}int IConvertible.ToInt32(IFormatProvider provider){throw new InvalidCastException();}long IConvertible.ToInt64(IFormatProvider provider){throw new InvalidCastException();}sbyte IConvertible.ToSByte(IFormatProvider provider){throw new InvalidCastException();}float IConvertible.ToSingle(IFormatProvider provider){throw new InvalidCastException();}string IConvertible.ToString(IFormatProvider provider){return ToString();}object IConvertible.ToType(Type conversionType, IFormatProvider provider){switch (Type.GetTypeCode(conversionType)){case TypeCode.String:return ((IConvertible)this).ToString(provider);case TypeCode.Object:if (conversionType == typeof(object) || conversionType == typeof(ObjectId)){return this;}if (conversionType == typeof(BsonObjectId)){return new BsonObjectId(this);}if (conversionType == typeof(BsonString)){return new BsonString(((IConvertible)this).ToString(provider));}break;}throw new InvalidCastException();}ushort IConvertible.ToUInt16(IFormatProvider provider){throw new InvalidCastException();}uint IConvertible.ToUInt32(IFormatProvider provider){throw new InvalidCastException();}ulong IConvertible.ToUInt64(IFormatProvider provider){throw new InvalidCastException();}}
}相关文章:
.NET生成MongoDB中的主键ObjectId
前言 因为很多场景下我们需要在创建MongoDB数据的时候提前生成好主键为了返回或者通过主键查询创建的业务,像EF中我们可以生成Guid来,本来想着要不要实现一套MongoDB中ObjectId的,结果发现网上各种各样的实现都有,不过好在阅读C#…...
BeautifulSoup+xpath+re+css简单复习+新的scrapy的学习
1.BeautifulSoupsoup BeautifulSoup(html,html.parser)all_icosoup.find(class_"DivTable") 2.xpath trs resp.xpath("//tbody[idcpdata]/tr") hong tr.xpath("./td[classchartball01 or classchartball20]/text()").extract() 这个意思是找…...
Python爬虫实战:从API获取数据
引言 在现代软件开发中,API已经成为获取数据的主要方式之一。API允许不同的软件应用程序相互通信,共享数据和功能。在本文中,我们将学习如何使用Python从API获取数据,并探讨其在实际应用中的价值。 目录 引言 二、API基础知识 …...
音频转换器哪个好?3款电脑软件+3款手机应用
在当今的数字时代,音频转换已成为许多用户日常的需求。为了帮助您找到最佳的音频转换工具,我们将介绍3款电脑软件和3款手机应用。这些工具都各有特点,能够满足不同用户的需求。 1.电脑软件篇 1.1金舟音频大师 金舟音频大师是一款多功能的音…...
惯性导航 | 运动学---运动模型
惯性导航 | 运动学---运动模型 IMU系统的运动学 IMU系统的运动学 惯性测量单元(IMU)已经非常普及了。我们在绝大多数电子设备中都能找到IMU:车辆、手机、手表、头盔,甚至足球当中都内置了IMU。它们的体积很小,安装在设…...
Java Web(十一)--JSON Ajax
JSON JSon在线文档: JSON 简介 JSON(JavaScript Object Notation, JS 对象标记) 是一种轻量级的数据交换格式。轻量级指的是跟xml做比较。数据交换指的是客户端和服务器之间业务数据的传递格式。 它基于 ECMAScript (W3C制定的JS规范)的一个子集,采…...
GL/gl.h: No such file or directory(CentOS8 QT5.12.12)
1.问题描述 新建的QT工程,出现如下问题: GL/gl.h: No such file or directory 2.原因分析 centos系统里面缺少opengl库 3.解决方法 运行命令: yum install mesa-libGL -devel -y...
【外设篇】-显示器
显示屏是一种电光转换工具,现在市面上的显示器都是LCD(Liquid Crystal Display,液晶显示器) 显示器参数介绍 对比度 是指画面黑与白的比值,对比度越高能使色彩表现越丰富,对比度越高,显示器的…...
可视化图文报表
Apache Echarts介绍 Apache Echarts是一款基于Javascript的数据可视化图表库,提供直观,生动,可交互,可个性化定制的数据可视化图表。 官网:Apache ECharts 入门案例: <!DOCTYPE html> <html>…...
CW023A-H035 CW023A-R230铜合金硬度材质书
CW023A-H035 CW023A-R230铜合金硬度材质书C2100W-O、C2680TWS-OL、C2200W-1/2H、C2800TS-O 、C2800T-H、C2800T-1/2H、C2700TS-O、C4430T-O、C2700T-O、C2700T-H、C2700T-OL、C2800TS-1/2H、C2800T-OL、C2700-O、C2800TS-H、C2700-H、C2700T-1/2H、C2600TS-1/2H、C2700-1/2H、C…...
Ribbon负载均衡:提升应用性能与可靠性的秘密武器(一)
本系列文章简介: 本系列文章将深入探讨Ribbon负载均衡的工作原理、应用场景和实践经验,帮助大家更好地理解和应用这一强大的技术。通过合理配置和优化Ribbon负载均衡,您可以为您的应用带来更高的性能和可靠性,从而获得竞争优势并满…...
python递归算法
递归算法 一、嵌套调用的过程二、递归的基本原则1、递归的基本原则2、无限递归调用3、正常递归调用4、阶乘问题5、力扣:231. 2 的幂6、力扣面试题 08.05. 递归乘法7、力扣、326. 3 的幂8、力扣342. 4的幂 一、嵌套调用的过程 def show1():print("show 1 run s…...
azure devops工具实践分析
对azure devops此工具的功能深挖,结合jira的使用经验的分析 1、在backlog的功能描述,可理解为需求项,这里包括了bug,从开发的角度修复bug也是个工作项,所以需求的范围是真正的需求(开发接收到的已经确认的…...
2024年2月19日-2月25日(全面进行+收集免费虚幻商城资源,20小时,合计2561小时,剩余7439小时)
试试周一到周五重点进行,周末抄写源码,周一晚上看书很快就在22:00睡着,早上可以看看视频教程,出租车上补觉。 执行如下: 周一: 8:01-9:20ue4 rpg(184…...
Ubuntu制作本地安装源
Ubuntu制作本地安装源 应用场景离线安装包的制作(可联网电脑)更新源安装软件 生成依赖关系在另外一台Ubuntu上离线安装安装 使用deb http方式安装安装nginx更新ubuntu数据库,并安装应用 应用场景 当我们需要在多台电脑安装同一个软件,并且软…...
java springmvc/springboot 项目通过HttpServletRequest对象获取请求体body工具类
请求 测试接口 获取到的 获取到打印出的json字符串里有空格这些,在json解析的时候正常解析为json对象了。 工具类代码 import lombok.extern.slf4j.Slf4j; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.we…...
新手怎么使用github?
GitHub新手使用指南,涵盖了从注册、创建仓库、版本控制基本操作到SSH密钥配置等关键步骤: 第一步:注册与登录 访问GitHub官方网站:https://github.com。点击页面右上角的"sign up"按钮开始注册账号。输入有效的电子邮…...
CSS_实现三角形和聊天气泡框
如何用css画出一个三角形 1、第一步 写一个正常的盒子模型,先给个正方形的div,便于观察,给div设置宽高和背景颜色 <body><div class"box"></div> </body> <style>.box {width: 100px;height: 100px…...
VPX基于全国产飞腾FT-2000+/64核+复旦微FPGA的计算刀片
6U VPX计算板 产品简介 产品特点 飞腾计算平台,国产化率100% VPX-MPU6902是一款基于飞腾FT-2000/64核的计算刀片,主频2.2GHz,负责业务数据流的管控和调度。搭配自带独立显示芯片的飞腾X100芯片,可用于于各类终端及服务器类应用场…...
ifcplusplus 示例 函数中英文 对照分析
有需求,需要分析 ifc c渲染,分析完,有 230个函数,才能完成一个加载,3d加载真的是大工程! 函数中英文对照表,方便 日后开发,整理思路顺畅!!!&#…...
使用docker在3台服务器上搭建基于redis 6.x的一主两从三台均是哨兵模式
一、环境及版本说明 如果服务器已经安装了docker,则忽略此步骤,如果没有安装,则可以按照一下方式安装: 1. 在线安装(有互联网环境): 请看我这篇文章 传送阵>> 点我查看 2. 离线安装(内网环境):请看我这篇文章 传送阵>> 点我查看 说明:假设每台服务器已…...
Linux应用开发之网络套接字编程(实例篇)
服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …...
应用升级/灾备测试时使用guarantee 闪回点迅速回退
1.场景 应用要升级,当升级失败时,数据库回退到升级前. 要测试系统,测试完成后,数据库要回退到测试前。 相对于RMAN恢复需要很长时间, 数据库闪回只需要几分钟。 2.技术实现 数据库设置 2个db_recovery参数 创建guarantee闪回点,不需要开启数据库闪回。…...
论文解读:交大港大上海AI Lab开源论文 | 宇树机器人多姿态起立控制强化学习框架(二)
HoST框架核心实现方法详解 - 论文深度解读(第二部分) 《Learning Humanoid Standing-up Control across Diverse Postures》 系列文章: 论文深度解读 + 算法与代码分析(二) 作者机构: 上海AI Lab, 上海交通大学, 香港大学, 浙江大学, 香港中文大学 论文主题: 人形机器人…...
k8s从入门到放弃之Ingress七层负载
k8s从入门到放弃之Ingress七层负载 在Kubernetes(简称K8s)中,Ingress是一个API对象,它允许你定义如何从集群外部访问集群内部的服务。Ingress可以提供负载均衡、SSL终结和基于名称的虚拟主机等功能。通过Ingress,你可…...
前端导出带有合并单元格的列表
// 导出async function exportExcel(fileName "共识调整.xlsx") {// 所有数据const exportData await getAllMainData();// 表头内容let fitstTitleList [];const secondTitleList [];allColumns.value.forEach(column > {if (!column.children) {fitstTitleL…...
Spring Boot+Neo4j知识图谱实战:3步搭建智能关系网络!
一、引言 在数据驱动的背景下,知识图谱凭借其高效的信息组织能力,正逐步成为各行业应用的关键技术。本文聚焦 Spring Boot与Neo4j图数据库的技术结合,探讨知识图谱开发的实现细节,帮助读者掌握该技术栈在实际项目中的落地方法。 …...
pikachu靶场通关笔记22-1 SQL注入05-1-insert注入(报错法)
目录 一、SQL注入 二、insert注入 三、报错型注入 四、updatexml函数 五、源码审计 六、insert渗透实战 1、渗透准备 2、获取数据库名database 3、获取表名table 4、获取列名column 5、获取字段 本系列为通过《pikachu靶场通关笔记》的SQL注入关卡(共10关࿰…...
tomcat入门
1 tomcat 是什么 apache开发的web服务器可以为java web程序提供运行环境tomcat是一款高效,稳定,易于使用的web服务器tomcathttp服务器Servlet服务器 2 tomcat 目录介绍 -bin #存放tomcat的脚本 -conf #存放tomcat的配置文件 ---catalina.policy #to…...
Python 高效图像帧提取与视频编码:实战指南
Python 高效图像帧提取与视频编码:实战指南 在音视频处理领域,图像帧提取与视频编码是基础但极具挑战性的任务。Python 结合强大的第三方库(如 OpenCV、FFmpeg、PyAV),可以高效处理视频流,实现快速帧提取、压缩编码等关键功能。本文将深入介绍如何优化这些流程,提高处理…...
