ASP.NET Core 3.1系列(18)——EFCore中执行原生SQL语句

news2024/11/24 3:00:39

1、前言

前一篇博客介绍了EFCore中常见的一些查询操作,使用LinqLambda结合实体类的操作相当方便。但在某些特殊情况下,我们仍旧需要使用原生SQL来获取数据。好在EFCore中提供了完整的方法支持原生SQL,下面开始介绍。

2、构建测试数据库

与之前一样,还是使用AuthorBook数据表,它们是一对多的关系,AuthorIdBook表中的外键。

Author表数据如下所示:

IdNameGenderAgeEmail
1张三3511111111@qq.com
2李四4022222222@qq.com
3王五3733333333@qq.com

Book表数据如下所示:

IdTitlePressPublicationTimePriceAuthorId
1《C程序设计》A出版社2022-01-01301
2《C++程序设计》B出版社2022-02-02451
3《Java程序设计》C出版社2022-03-03602
4《C#程序设计》D出版社2022-04-04552

Author代码如下:

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

// Code scaffolded by EF Core assumes nullable reference types (NRTs) are not used or disabled.
// If you have enabled NRTs for your project, then un-comment the following line:
// #nullable disable

namespace App.Models
{
    public partial class Author
    {
        public Author()
        {
            Book = new HashSet<Book>();
        }

        /// <summary>
        /// 主键
        /// </summary>
        [Key]
        public int Id { get; set; }

        /// <summary>
        /// 姓名
        /// </summary>
        [StringLength(20)]
        public string Name { get; set; }

        /// <summary>
        /// 性别
        /// </summary>
        [StringLength(2)]
        public string Gender { get; set; }

        /// <summary>
        /// 年龄
        /// </summary>
        public int? Age { get; set; }

        /// <summary>
        /// 邮箱
        /// </summary>
        [StringLength(30)]
        public string Email { get; set; }

        /// <summary>
        /// 导航属性
        /// </summary>
        [InverseProperty("Author")]
        public virtual ICollection<Book> Book { get; set; }
    }
}

Book代码如下:

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

// Code scaffolded by EF Core assumes nullable reference types (NRTs) are not used or disabled.
// If you have enabled NRTs for your project, then un-comment the following line:
// #nullable disable

namespace App.Models
{
    public partial class Book
    {
        /// <summary>
        /// 主键
        /// </summary>
        [Key]
        public int Id { get; set; }

        /// <summary>
        /// 书名
        /// </summary>
        [StringLength(20)]
        public string Title { get; set; }

        /// <summary>
        /// 出版社
        /// </summary>
        [StringLength(20)]
        public string Press { get; set; }

        /// <summary>
        /// 出版时间
        /// </summary>
        [Column(TypeName = "datetime")]
        public DateTime? PublicationTime { get; set; }

        /// <summary>
        /// 价格
        /// </summary>
        [Column(TypeName = "money")]
        public decimal? Price { get; set; }

        /// <summary>
        /// 外键:AuthorId
        /// </summary>
        public int? AuthorId { get; set; }

        /// <summary>
        /// 导航属性
        /// </summary>
        [ForeignKey(nameof(AuthorId))]
        [InverseProperty("Book")]
        public virtual Author Author { get; set; }
    }
}

DaoDbContext代码如下:

using App.Models;
using Microsoft.EntityFrameworkCore;

// Code scaffolded by EF Core assumes nullable reference types (NRTs) are not used or disabled.
// If you have enabled NRTs for your project, then un-comment the following line:
// #nullable disable

namespace App.Context
{
    public partial class DaoDbContext : DbContext
    {
        public DaoDbContext()
        {
        }

        public DaoDbContext(DbContextOptions<DaoDbContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Author> Author { get; set; }
        public virtual DbSet<Book> Book { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer("Data Source=DSF-PC;Initial Catalog=Dao;User ID=sa;Password=123456;");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Book>(entity =>
            {
                entity.HasOne(d => d.Author)
                    .WithMany(p => p.Book)
                    .HasForeignKey(d => d.AuthorId)
                    .OnDelete(DeleteBehavior.Cascade)
                    .HasConstraintName("FK_Book_Author");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}

3、执行原生SQL查询操作

3.1、FromSqlInterpolated

如果是针对单表的查询操作,可以使用FromSqlInterpolated方法,但是该方法有以下局限性:

  • 只支持单表查询,不支持Join
  • 必须返回全部列
  • 结果集中的列名必须与数据库中的列名对应

下面将查询查询Author表中Name='张三'Age>30的记录,代码如下:

using App.Context;
using App.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;

namespace App.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AuthorController : ControllerBase
    {
        protected readonly DaoDbContext _dbContext;

        public AuthorController(DaoDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        [HttpGet]
        public ActionResult<List<Author>> Get()
        {
            return GetAuthors("张三", 30);
        }

        private List<Author> GetAuthors(string name, int age)
        {
            return _dbContext.Set<Author>()
                             .FromSqlInterpolated(@$"select * from Author where Name={name} and Age>{age}")
                             .ToList();
        }
    }
}

运行结果如下所示:

[{"id":1,"name":"张三","gender":"男","age":35,"email":"11111111@qq.com","book":[]}]

如果希望查询出Author对应的Book,也可以通过Include实现,EFCore支持FromSqlInterpolatedLambda一起使用,代码如下:

using App.Context;
using App.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;

namespace App.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AuthorController : ControllerBase
    {
        protected readonly DaoDbContext _dbContext;

        public AuthorController(DaoDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        [HttpGet]
        public ActionResult<List<Author>> Get()
        {
            return GetAuthors("张三", 30);
        }

        private List<Author> GetAuthors(string name, int age)
        {
            return _dbContext.Set<Author>()
                             .FromSqlInterpolated(@$"select * from Author where Name={name} and Age>{age}")
                             .Include(p => p.Book)
                             .ToList();
        }
    }
}

运行结果如下所示:

[
    {
        "id": 1,
        "name": "张三",
        "gender": "男",
        "age": 35,
        "email": "11111111@qq.com",
        "book": [
            {
                "id": 1,
                "title": "《C程序设计》",
                "press": "A出版社",
                "publicationTime": "2021-01-01T00:00:00",
                "price": 30.0000,
                "authorId": 1
            },
            {
                "id": 2,
                "title": "《C++程序设计》",
                "press": "B出版社",
                "publicationTime": "2021-02-02T00:00:00",
                "price": 45.0000,
                "authorId": 1
            }
        ]
    }
]

3.2、FromSqlRaw

针对单表的查询也可以使用FromSqlRaw方法,与FromSqlInterpolated类似,该方法也必须返回全部列,代码如下:

using App.Context;
using App.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;

namespace App.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AuthorController : ControllerBase
    {
        protected readonly DaoDbContext _dbContext;

        public AuthorController(DaoDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        [HttpGet]
        public ActionResult<List<Author>> Get()
        {
            return GetAuthors("张三", 30);
        }

        private List<Author> GetAuthors(string name, int age)
        {
            SqlParameter[] parameters =
            {
                new SqlParameter(@"Name", name),
                new SqlParameter(@"Age", age)
            };
            return _dbContext.Set<Author>()
                             .FromSqlRaw("select * from Author where Name=@Name and Age>@Age", parameters)
                             .ToList();
        }
    }
}

运行结果如下所示:

[{"id":1,"name":"张三","gender":"男","age":35,"email":"11111111@qq.com","book":[]}]

FromSqlRaw方法也可以与Lambda一起使用,代码如下:

using App.Context;
using App.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;

namespace App.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AuthorController : ControllerBase
    {
        protected readonly DaoDbContext _dbContext;

        public AuthorController(DaoDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        [HttpGet]
        public ActionResult<List<Author>> Get()
        {
            return GetAuthors(1);
        }

        private List<Author> GetAuthors(int id)
        {
            SqlParameter[] parameters =
            {
                new SqlParameter(@"Id", id),
            };
            return _dbContext.Set<Author>()
                             .FromSqlRaw("select * from Author where Id>@Id", parameters)
                             .OrderByDescending(p => p.Age)
                             .Include(p => p.Book)
                             .ToList();
        }
    }
}

运行结果如下所示:

[
    {
        "id": 2,
        "name": "李四",
        "gender": "女",
        "age": 40,
        "email": "22222222@qq.com",
        "book": [
            {
                "id": 3,
                "title": "《Java程序设计》",
                "press": "C出版社",
                "publicationTime": "2021-03-03T00:00:00",
                "price": 60.0000,
                "authorId": 2
            },
            {
                "id": 4,
                "title": "《C#程序设计》",
                "press": "D出版社",
                "publicationTime": "2021-04-04T00:00:00",
                "price": 55.0000,
                "authorId": 2
            }
        ]
    },
    {
        "id": 3,
        "name": "王五",
        "gender": "男",
        "age": 37,
        "email": "33333333@qq.com",
        "book": []
    }
]

4、执行原生SQL非查询操作

4.1、ExecuteSqlInterpolated

如果希望执行增删改等非查询操作,可以使用ExecuteSqlInterpolated方法,下面给Author表添加一条记录,代码如下:

using App.Context;
using App.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace App.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AuthorController : ControllerBase
    {
        protected readonly DaoDbContext _dbContext;

        public AuthorController(DaoDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        [HttpGet]
        public ActionResult<string> Get()
        {
            int result = AddAuthor(new Author
            {
                Name = "AAA",
                Gender = "男",
                Age = 33,
                Email = "44444444@qq.com"
            });
            return result > 0 ? "添加数据成功" : "添加数据失败";
        }

        private int AddAuthor(Author author)
        {
            string name = author.Name;
            string gender = author.Gender;
            int age = author.Age.HasValue ? author.Age.Value : 0;
            string email = author.Email;
            return _dbContext.Database.ExecuteSqlInterpolated(@$"insert into Author(Name,Gender,Age,Email) values({name},{gender},{age},{email})");
        }
    }
}

运行结果如下所示:

添加数据成功

在这里插入图片描述

4.2、ExecuteSqlRaw

ExecuteSqlRaw方法也可以执行增删改等非查询操作,代码如下:

using App.Context;
using App.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;

namespace App.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AuthorController : ControllerBase
    {
        protected readonly DaoDbContext _dbContext;

        public AuthorController(DaoDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        [HttpGet]
        public ActionResult<string> Get()
        {
            int result = AddAuthor(new Author
            {
                Name = "BBB",
                Gender = "女",
                Age = 42,
                Email = "55555555@qq.com"
            });
            return result > 0 ? "添加数据成功" : "添加数据失败";
        }

        private int AddAuthor(Author author)
        {
            SqlParameter[] parameters =
            {
                new SqlParameter(@"Name", author.Name),
                new SqlParameter(@"Gender", author.Gender),
                new SqlParameter(@"Age", author.Age),
                new SqlParameter(@"Email", author.Email)
            };
            return _dbContext.Database.ExecuteSqlRaw("insert into Author(Name,Gender,Age,Email) values(@Name,@Gender,@Age,@Email)", parameters);
        }
    }
}

运行结果如下所示:

添加数据成功

在这里插入图片描述

5、执行数据库事务

如果希望执行数据库事务,可以使用BeginTransaction方法,下面代码执行了一个包含InsertUpdate的事务:

using App.Context;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace App.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AuthorController : ControllerBase
    {
        protected readonly DaoDbContext _dbContext;

        public AuthorController(DaoDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        [HttpGet]
        public ActionResult<string> Get()
        {
            using (var transaction = _dbContext.Database.BeginTransaction())
            {
                try
                {
                    _dbContext.Database.ExecuteSqlRaw("insert into Author(Name,Gender,Age,Email) values('CCC','男',45,'66666666@qq.com')");
                    _dbContext.Database.ExecuteSqlRaw("update Author set Name='张三三' where Name='张三'");
                    transaction.Commit();
                    return "执行事务成功";
                }
                catch
                {
                    transaction.Rollback();
                    return "执行事务失败";
                }
            }
        }
    }
}

运行结果如下所示:

执行事务成功

在这里插入图片描述

6、封装SqlHelper

上面的查询方法都必须返回全部列,而在实际开发过程中往往是按需查询列,因此我们还是需要自行封装一个SqlHelper,代码如下:

SqlHelper.cs代码:

using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;

namespace App
{
    public class SqlHelper
    {
        /// <summary>
        /// 执行查询操作,返回DataTable
        /// </summary>
        /// <param name="dbContext">数据库上下文</param>
        /// <param name="commandText">命令语句</param>
        /// <param name="commandType">命令类型</param>
        /// <param name="parameters">格式化参数集合</param>
        /// <returns>DataTable</returns>
        public static DataTable ExecuteQuery(DbContext dbContext, string commandText, CommandType commandType, params SqlParameter[] parameters)
        {
            DbConnection connection = dbContext.Database.GetDbConnection();
            if (connection.State != ConnectionState.Open)
            {
                connection.Open();
            }

            // 设置Command
            using DbCommand command = connection.CreateCommand();
            command.CommandText = commandText;
            command.CommandType = commandType;
            if (parameters != null && parameters.Length > 0)
            {
                command.Parameters.AddRange(parameters);
            }

            // 查询数据
            using SqlDataAdapter adapter = new SqlDataAdapter(command as SqlCommand);
            try
            {
                DataTable dataTable = new DataTable();
                adapter.Fill(dataTable);
                return dataTable;
            }
            catch
            {
                return null;
            }
            finally
            {
                command.Parameters.Clear();
            }
        }

        /// <summary>
        /// 执行查询操作,返回DbDataReader
        /// </summary>
        /// <param name="dbContext">数据库上下文</param>
        /// <param name="commandText">命令语句</param>
        /// <param name="commandType">命令类型</param>
        /// <param name="parameters">格式化参数集合</param>
        /// <returns>DbDataReader</returns>
        public static DbDataReader ExecuteReader(DbContext dbContext, string commandText, CommandType commandType, params SqlParameter[] parameters)
        {
            DbConnection connection = dbContext.Database.GetDbConnection();
            if (connection.State != ConnectionState.Open)
            {
                connection.Open();
            }

            // 设置Command
            using DbCommand command = connection.CreateCommand();
            command.CommandText = commandText;
            command.CommandType = commandType;
            if (parameters != null && parameters.Length > 0)
            {
                command.Parameters.AddRange(parameters);
            }

            // 返回DataReader
            try
            {
                return command.ExecuteReader();
            }
            catch
            {
                return null;
            }
            finally
            {
                command.Parameters.Clear();
            }
        }

        /// <summary>
        /// 执行查询操作,返回第一行第一列
        /// </summary>
        /// <param name="dbContext">数据库上下文</param>
        /// <param name="commandText">命令语句</param>
        /// <param name="commandType">命令类型</param>
        /// <param name="parameters">格式化参数集合</param>
        /// <returns>第一行第一列</returns>
        public static object ExecuteScalar(DbContext dbContext, string commandText, CommandType commandType, params SqlParameter[] parameters)
        {
            DbConnection connection = dbContext.Database.GetDbConnection();
            if (connection.State != ConnectionState.Open)
            {
                connection.Open();
            }

            // 设置Command
            using DbCommand command = connection.CreateCommand();
            command.CommandText = commandText;
            command.CommandType = commandType;
            if (parameters != null && parameters.Length > 0)
            {
                command.Parameters.AddRange(parameters);
            }

            // 返回第一行第一列
            try
            {
                return command.ExecuteScalar();
            }
            catch
            {
                return null;
            }
            finally
            {
                command.Parameters.Clear();
            }
        }

        /// <summary>
        /// 执行非查询操作,返回受影响的行数
        /// </summary>
        /// <param name="dbContext">数据库上下文</param>
        /// <param name="commandText">命令语句</param>
        /// <param name="commandType">命令类型</param>
        /// <param name="parameters">格式化参数集合</param>
        /// <returns>受影响的行数</returns>
        public static int ExecuteNonQuery(DbContext dbContext, string commandText, CommandType commandType, params SqlParameter[] parameters)
        {
            DbConnection connection = dbContext.Database.GetDbConnection();
            if (connection.State != ConnectionState.Open)
            {
                connection.Open();
            }

            // 设置Command
            using DbCommand command = connection.CreateCommand();
            command.CommandText = commandText;
            command.CommandType = commandType;
            if (parameters != null && parameters.Length > 0)
            {
                command.Parameters.AddRange(parameters);
            }

            // 返回受影响的行数
            try
            {
                return command.ExecuteNonQuery();
            }
            catch
            {
                return 0;
            }
            finally
            {
                command.Parameters.Clear();
            }
        }

        /// <summary>
        /// 执行数据库事务,返回受影响的行数
        /// </summary>
        /// <param name="dbContext">数据库上下文</param>
        /// <param name="commands">命令集合</param>
        /// <returns>受影响的行数</returns>
        public static int ExecuteTransaction(DbContext dbContext, List<SingleCommand> commands)
        {
            DbConnection connection = dbContext.Database.GetDbConnection();
            if (connection.State != ConnectionState.Open)
            {
                connection.Open();
            }

            // 开启事务
            using DbTransaction transaction = connection.BeginTransaction();
            try
            {
                foreach (var item in commands)
                {
                    DbCommand command = connection.CreateCommand();
                    command.CommandText = item.CommandText;
                    command.CommandType = CommandType.Text;
                    command.Transaction = transaction;
                    if (item.Parameters.Count > 0)
                    {
                        command.Parameters.AddRange(item.Parameters.ToArray());
                    }
                    command.ExecuteNonQuery();
                }

                // 提交事务
                transaction.Commit();
                return 1;
            }
            catch
            {
                // 回滚事务
                transaction.Rollback();
                return 0;
            }
        }
    }
}

SingleCommand.cs代码:

using Microsoft.Data.SqlClient;
using System.Collections.Generic;

namespace App
{
    public class SingleCommand
    {
        /// <summary>
        /// 命令语句
        /// </summary>
        public string CommandText { get; set; }

        /// <summary>
        /// 格式化参数集合
        /// </summary>
        public List<SqlParameter> Parameters { get; set; }
    }
}

最后在Controller调用即可,代码如下:

using App.Context;
using App.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;

namespace App.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AuthorController : ControllerBase
    {
        protected readonly DaoDbContext _dbContext;

        public AuthorController(DaoDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        [HttpGet]
        public ActionResult<DataTable> GetAuthorsById()
        {
            SqlParameter parameter = new SqlParameter(@"Id", 1);
            return SqlHelper.ExecuteQuery(_dbContext, "select Id,Name,Age from Author where Id>@Id", CommandType.Text, parameter);
        }

        [HttpGet]
        public ActionResult<List<Author>> GetAuthorsByAge()
        {
            List<Author> list = new List<Author>();
            SqlParameter parameter = new SqlParameter(@"Age", 35);
            DbDataReader reader = SqlHelper.ExecuteReader(_dbContext, "select Id,Name,Age from Author where Age>@Age", CommandType.Text, parameter);
            while (reader.Read())
            {
                list.Add(new Author
                {
                    Id = Convert.ToInt32(reader["Id"]),
                    Name = reader["Name"] == DBNull.Value ? null : Convert.ToString(reader["Name"]),
                    Age = reader["Id"] == DBNull.Value ? new Nullable<int>() : Convert.ToInt32(reader["Age"])
                });
            }
            return list;
        }

        [HttpGet]
        public ActionResult<int> GetAuthorsCount()
        {
            object obj = SqlHelper.ExecuteScalar(_dbContext, "select count(*) from Author", CommandType.Text);
            return Convert.ToInt32(obj);
        }

        [HttpGet]
        public ActionResult<string> UpdateAuthorById()
        {
            SqlParameter[] parameters =
            {
                new SqlParameter(@"Id", 1),
                new SqlParameter(@"Email", "12345678@163.com")
            };
            int result = SqlHelper.ExecuteNonQuery(_dbContext, "update Author set Email=@Email where Id=@Id", CommandType.Text, parameters);
            return result > 0 ? "修改邮箱成功" : "修改邮箱失败";
        }

        [HttpGet]
        public ActionResult<string> GetTransactionResult()
        {
            List<SingleCommand> commands = new List<SingleCommand>
            {
                new SingleCommand()
                {
                    CommandText = "insert into Author values(@Name,@Gender,@Age,@Email)",
                    Parameters = new List<SqlParameter>
                    {
                        new SqlParameter(@"Name", "赵六"),
                        new SqlParameter(@"Gender", "女"),
                        new SqlParameter(@"Age", 39),
                        new SqlParameter(@"Email", "12345678@163.com")
                    }
                },
                new SingleCommand()
                {
                    CommandText = "update Author set Age=@Age where Name=@Name",
                    Parameters = new List<SqlParameter>
                    {
                        new SqlParameter(@"Name", "张三"),
                        new SqlParameter(@"Age", 59)
                    }
                },
            };
            int result = SqlHelper.ExecuteTransaction(_dbContext, commands);
            return result > 0 ? "事务执行成功" : "事务执行失败";
        }
    }
}

GetAuthorsById结果如下:

[
 {"id":2,"name":"李四","age":40},
 {"id":3,"name":"王五","age":37}
]

GetAuthorsByAge结果如下:

[
 {"id":2,"name":"李四","gender":null,"age":40,"email":null,"book":[]},
 {"id":3,"name":"王五","gender":null,"age":37,"email":null,"book":[]}
]

GetAuthorsCount结果如下:

3

UpdateAuthorById结果如下:

修改邮箱成功

在这里插入图片描述
GetTransactionResult结果如下:

事务执行成功

在这里插入图片描述

7、结语

本文主要介绍了如何在EFCore中执行原生SQL的方法。在某些特殊情况下,直接执行原生语句往往会更方便且更高效,因此EFCore虽好,也别忘了SQL

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

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

相关文章

Radare2 框架介绍及使用

Radare2 框架介绍及使用 欢迎入群交流 radare2 这是整个框架的核心工具&#xff0c;它具有debugger和Hexeditor的核心功能&#xff0c;使您能够像打开普通的文件一样&#xff0c;打开许多输入/输出源&#xff0c;包括磁盘、网络连接、内核驱动和处于调试中的进程等。 它实现了…

旧版本金庸群侠传3D新Unity重置修复版入门-lua”脚本“

金庸3DUnity重置入门系列文章 金庸3dUnity重置入门 - lua 语法 金庸3dUnity重置入门 - UniTask插件 金庸3dUnity重置入门 - Cinemachine 动画 金庸3dUnity重置入门 - 大世界实现方案 金庸3dUnity重置入门 - 素材极限压缩 (部分可能放到付费博客&#xff09; 2022年底~20…

Apifox和Eolink两个测试工具谁最实用?

目前行业内有 postman、jmeter 为代表开源 Api 工具派系&#xff0c;我想对大家对这两个词并不陌生。虽然它们能解决基本的接口测试&#xff0c;但是无法解决接口链路上的所有问题&#xff0c;一个工具难以支持整个过程。在国内&#xff0c;我们可以看到有国产 API 管理工具&am…

Spring Cloud 微服务讲义

Spring Cloud 微服务讲义第一部分 微服务架构第 1 节 互联网应用架构演进第 2 节 微服务架构体现的思想及优缺点第 3 节 微服务架构中的核心概念第二部分 Spring Cloud 综述第 1 节 Spring Cloud 是什么第 2 节 Spring Cloud 解决什么问题第 3 节 Spring Cloud 架构3.1 Spring …

CCES软件做开发,如果仿真器连不进目标板怎么解决?(Failed to connect to processor)

ADI的DSP调试&#xff0c;我在Visual DSP软件下写过一个详细的帖子&#xff0c;来说明仿真器如果连不进目标板&#xff0c;可能存在的几种问题以及解决办法&#xff0c;现在在CCES软件下遇到了同样的问题&#xff0c;所以准备再写一个帖子说明一下。 我们都知道ADI的DSP&#…

智慧工地管理平台系统厂家哪家强|喜讯科技

喜讯科技针对施工现场涉及面广&#xff0c;多种元素交叉&#xff0c;状况较为复杂&#xff0c;如人员出入、机械运行、物料运输等工程项目管理在一定程度上存在着决策层看不清、管理层管不住、执行层做不好的问题。 围绕施工现场管理&#xff0c;构建全方位的智能监控防范体系弥…

Redis——Linux下安装以及命令操作

一、概述 redis是什么&#xff1f; Redis&#xff08;Remote Dictionary Server )&#xff0c;即远程字典服务 是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库&#xff0c;并提供多种语言的API。 是一款高性能的NOSQL系列的非关系型…

每日一题:冒泡排序

每日一题&#xff1a;冒泡排序每日一题:冒泡排序第一种写法&#xff1a;第二种写法&#xff1a;每日一题:冒泡排序 冒泡排序是八大排序中较为简单的一种&#xff0c;具体详细可见&#xff1a;冒泡排序_百度百科 (baidu.com) 我们重点来看冒泡排序的步骤&#xff1a; 冒泡排序…

程序员如何写游戏搞钱?

ConcernedApe&#xff0c;一个叫做Eric Barone的程序员研发了一款叫做星露谷的小游戏&#xff0c;以乡村经营生活为核心&#xff0c;打造了一个虚拟的小世界&#xff0c;在这个小世界&#xff0c;你可以种植农作物&#xff0c;经营农场并挖矿钓鱼。 其中钓鱼的玩法是十分新颖的…

Git常见问题

1.拉取的项目很大&#xff0c;如1G以上&#xff0c;此时报错early EOF 具体报错如下&#xff1a; Cloning into csp-doc... remote: Counting objects: 6061, done. remote: Compressing objects: 100% (4777/4777), done. error: RPC failed; curl 18 transfer closed with …

Spring - FactoryBean扩展实战_MyBatis-Spring 启动过程源码解读

文章目录PrePreMyBatis-Spring 组件扩展点org.mybatis.spring.SqlSessionFactoryBeanInitializingBean扩展接口 afterPropertiesSetFactoryBean 扩展接口 getObjectApplicationListener扩展接口 onApplicationEvent扩展点org.mybatis.spring.mapper.MapperFactoryBeanSqlSessio…

【Linux基本命令归纳整理】

Linux 是一套免费使用和自由传播的类 Unix 操作系统&#xff0c;是一个基于 POSIX 和 UNIX 的多用户、多任务、支持多线程和多 CPU 的操作系统。严格来讲&#xff0c;Linux 这个词本身只表示 Linux 内核&#xff0c;但实际上人们已经习惯了用 Linux 来形容整个基于 Linux 内核&…

Day40——Dp专题

文章目录三、01背包8.分割等和子集9.最后一块石头的重量 II10.目标和11. 一和零三、01背包 8.分割等和子集 题目链接&#xff1a;416. 分割等和子集 - 力扣&#xff08;LeetCode&#xff09; 思路&#xff1a;我们构造两个子集使得两个子集的和相等&#xff0c;其实就是让我…

JavaScript:初始JS 以及 基础语法

前端三件套&#xff1a; HTML: 生成网页控件 例如&#xff1a;生成 文本框 多选框 下拉列表 等 (人的身体) CSS: 修饰网页上的控件 例如&#xff1a;修饰文本框为圆形 &#xff08;人的衣服&#xff09; JavaSript: 在这些控件上添加逻辑 例如&#xff1a;获取文本框的值 然…

哈工大体系结构lab3 —— 流水线处理器的verilog实现

流水线处理器的verilog实现 是的我刚刚验收完最后一个实验&#xff0c;所以怀着激动的心情&#xff0c;把当时其中一个留档的代码发出来&#xff0c;还算较为清晰&#xff0c;仅供没有思路的同学参考。造完cache&#xff0c;我的生活终于可以恢复正轨了&#xff0c;这几天折磨的…

web安全之SQL盲注的靶场练习和分析

目录 SQL盲注-报错回显盲注 SQL盲注-时间盲注 SQL盲注-布尔盲注 SQL盲注-报错回显盲注 在burp里面进行动态抓包&#xff0c;判断符号闭环&#xff0c;如图明显为闭环 列数3时报错&#xff0c;判断当前列数为2 强行报错注入 &#xff0c;如图获取到版本号 uname1212 unio…

h5视频落地页知识点整理

一、视频在苹果中自动播放&#xff08;借助微信SDK&#xff09; 1.引入微信SDK <script src"http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script> 2. document.addEventListener(WeixinJSBridgeReady, function() { const timer setInte…

如何签署exe或Windows应用程序?

本文您将了解为什么要签署Windows应用程序以及如何签署EXE或Windows应用程序的步骤指南。 代码签名是一种确保软件来自经过验证的正版软件发行商的方法。使用代码签名证书唱WindowsEXE文件可确保可执行文件或Windows应用程序不会被恶意行为者更改或修改。 Windows应用程序签名…

2022年NPDP新版教材知识集锦--【第五章节】(2)

《产品经理认证(NPDP)知识体系指南(第2版)》已于2022年4月正式上架发行&#xff0c;新版教材自2022年11月NPDP考试起使用。将新版NPDP教材中的相关知识点进行了整理汇总&#xff0c;包括详细设计与规格阶段相关内容&#xff0c;快来看看吧。 【市场研究工具】(全部内容获取文末…

华为机试 - 无向图染色

目录 题目描述 输入描述 输出描述 用例 题目解析 算法源码 题目描述 给一个无向图染色&#xff0c;可以填红黑两种颜色&#xff0c;必须保证相邻两个节点不能同时为红色&#xff0c;输出有多少种不同的染色方案&#xff1f; 输入描述 第一行输入M(图中节点数) N(边数) …