.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();}}
}

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

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

相关文章

探索IP地址定位工具:解读IP数据云的功能与优势

在当今数字化时代&#xff0c;IP地址定位工具成为了许多领域中不可或缺的技术支持&#xff0c;为网络安全、地理定位服务和个性化推荐等提供了重要数据支持。其中&#xff0c;IP数据云作为一种领先的IP地址定位工具&#xff0c;具有一系列功能和优势&#xff0c;本文将对其进行…

SpringCloud认识微服务

文章目录 1.1.单体架构1.2.分布式架构1.3.微服务1.4.SpringCloud1.5.总结 随着互联网行业的发展&#xff0c;对服务的要求也越来越高&#xff0c;服务架构也从单体架构逐渐演变为现在流行的微服务架构。这些架构之间有怎样的差别呢&#xff1f; 微服务架构是一种架构模式&…

三种方法用c语言求最大公约数以及最小公倍数

学习目标&#xff1a; 掌握求最大公约数&#xff08;最小公倍数&#xff09;的三种基本方法 学习内容&#xff1a; 1.一大一小取其小&#xff0c;剖根问底取公约 意思是从一大一小两个数当中&#xff0c;我们取较小的那个数&#xff08;min&#xff09;进行剖析&#xff0c;试…

【Ubuntu】解决Ubuntu 22.04开机显示器颜色(高对比度/反色)异常的问题

使用Ubuntu 22.04时强制关机了一下&#xff08;make -j16把电脑搞崩了&#xff09;&#xff0c;开机后系统显示的颜色异常&#xff0c;类似高对比度或反色&#xff0c;如下图。看着很难受&#xff0c;字体也没办法辨认。还好之前遇到过类似的问题&#xff0c;应该是一个配置文件…

JavaWeb——005 请求响应 分层解耦(Postman、三层架构、IOC、DI、注解)

SpringBootWeb请求响应 这里写目录标题 SpringBootWeb请求响应前言1. 请求1.1 Postman1.1.1 介绍1.1.2 安装 1.2 简单参数1.2.1 原始方式1.2.2 SpringBoot方式1.2.3 参数名不一致 1.3 实体参数1.3.1 简单实体对象1.3.2 复杂实体对象 1.4 数组集合参数1.4.1 数组1.4.2 集合 1.5 …

创建型设计模式 - 建造者设计模式 - JAVA

建造者设计模式 一. 简介二. 使用场景分析三. 代码案例3.1 创建ComputerBuilder 类3.2 修改子类3.3 修改工厂3.4 测试 四. 建造者模式案例 前言 这是我在这个网站整理的笔记,有错误的地方请指出&#xff0c;关注我&#xff0c;接下来还会持续更新。 作者&#xff1a;神的孩子都…

探索 SPA 与 MPA:前端架构的选择与权衡

查看本专栏目录 关于作者 还是大剑师兰特&#xff1a;曾是美国某知名大学计算机专业研究生&#xff0c;现为航空航海领域高级前端工程师&#xff1b;CSDN知名博主&#xff0c;GIS领域优质创作者&#xff0c;深耕openlayers、leaflet、mapbox、cesium&#xff0c;canvas&#x…

Python 实现 OSC 指标计算 (变动速率线):股票技术分析的利器系列(14)

Python 实现 OSC 指标计算 (变动速率线&#xff09;&#xff1a;股票技术分析的利器系列&#xff08;14&#xff09; 介绍算法公式 代码rolling函数介绍核心代码计算OSC 完整代码 介绍 OSC&#xff08;变动速率线&#xff09;是一种技术指标&#xff0c;通过计算价格的变动速率…

飞行员还是电话接线员?软件开发人员消亡的预测是荒谬的

Stability AI 首席执行官 Emad Mostaque最近因其大胆的预测“五年内将不再有程序员”而成为头条新闻。虽然此类声明在社交媒体上很受欢迎&#xff0c;但它们并不能准确反映创造力在复杂软件开发中的作用的现实。是的&#xff0c;人工智能将深刻改变软件工程行业&#xff0c;但这…

Spring的定时任务不生效、不触发,一些可能的原因,和具体的解决方法。

1 . 未在启动类上加 EnableScheduling 注解 原因&#xff1a;未在Spring Boot应用主类上添加EnableScheduling注解或未在XML配置文件中配置定时任务的启用。解决方法&#xff1a;确保在应用的配置类上添加EnableScheduling注解&#xff0c;启用定时任务。 2 . cron 表达式书写…

R语言使用dietaryindex包计算NHANES数据多种健康饮食指数 (HEI等)(1)

健康饮食指数 (HEI) 是评估一组食物是否符合美国人膳食指南 (DGA) 的指标。Dietindex包提供用户友好的简化方法&#xff0c;将饮食摄入数据标准化为基于指数的饮食模式&#xff0c;从而能够评估流行病学和临床研究中对这些模式的遵守情况&#xff0c;从而促进精准营养。 该软件…

自动从金蝶取数,做BI报表的工具,快来长见识!

技术越进步&#xff0c;分析工具越智能&#xff0c;如今做数据分析、数据可视化&#xff0c;不仅能连接金蝶系统&#xff0c;更能直接从金蝶ERP中取数做分析&#xff0c;自动输出BI数据可视化分析报表。这就是奥威-金蝶BI方案。 是骡子是马&#xff0c;牵出来遛遛就知道&#…

【C++】拿下! C++中的内存管理

内存管理 1 C 的内存分布2 C语言的内存管理3 C的内存管理3.1 内置类型操作3.2 自定义类型操作 4 operator new与operator delete函数&#xff08;重点&#xff09;5 new和delete的实现原理5.1 内置类型5.2 自定义类型new的原理delete的原理new T[ N ] 的原理lete[]的原理 6 总结…

day02_前后端环境搭建(前端工程搭建,登录功能说明,后端项目搭建)

文章目录 1. 软件开发介绍1.1 软件开发流程1.2 角色分工1.3 软件环境1.4 系统的分类 2. 尚品甄选项目介绍2.1 电商基本概念2.1.1 电商简介2.1.2 电商模式B2BB2CB2B2CC2BC2CO2O 2.2 业务功能介绍2.3 系统架构介绍2.4 前后端分离开发 3. 前端工程搭建3.1 Element-Admin简介3.2 El…

idea打包报错,clean、package报错

一、idea在打包时&#xff0c;点击clean或package报错如下&#xff1a; Error running ie [clean]: No valid Maven installation found. Either set the home directory in the configuration dialog or set the M2_HOME environment variable on your system. 示例图&#xf…

深入理解分库、分表、分库分表

前言 分库分表&#xff0c;是企业里面比较常见的针对高并发、数据量大的场景下的一种技术优化方案&#xff0c;所谓"分库分表"&#xff0c;根本就不是一件事儿&#xff0c;而是三件事儿&#xff0c;他们要解决的问题也都不一样&#xff0c;这三个事儿分别是"只…

C语言:字符函数 字符串函数 内存函数

C语言&#xff1a;字符函数 & 字符串函数 & 内存函数 字符函数字符分类函数字符转换函数tolowertoupper 字符串函数strlenstrcpystrcatstrcmpstrstrstrtok 内存函数memcpymemmovememsetmemcmp 字符函数 顾名思义&#xff0c;字符函数就是作用于字符的函数&#xff0c;…

【MySQL | 第一篇】undo log、redo log、bin log三者之间的区分?

undo log、redo log、bin log三者之间的区分&#xff1f; 从 产生的时间点、日志内容、用途 三方面展开论述即可 1.undo log——撤销日志 时间点&#xff1a;事务开始之前产生&#xff0c;根据当前版本的数据生成一个undo log&#xff0c;也保存在事务开始之前 作用&#xf…

【亚马逊云新春特辑②】构生成式 AI 文生图工具之借助ControlNet进行AI绘画创作【生成艺术二维码】

文章目录 1.1 生成艺术二维码1&#xff09;制作基础二维码2&#xff09;确定艺术风格3&#xff09;生成艺术二维码4&#xff09;结果优化 AIGC 的可控性是它进入实际生产最关键的一环。在此之前&#xff0c;许多用户希望 AI 生成的结果尽可能符合要求&#xff0c;但都不尽如人意…

linux centos7.9改dns和ip

vi /etc/sysconfig/network-scripts/ifcfg-ens32 &#xff1a;wq后 重启网络服务 systemctl restart network —————————————————————————— 篇外话题 软件下载 xshell可以从腾讯软件中心下载