ASP.NET Core MVC 项目 AOP之Authorization

news/2024/4/19 10:09:14/文章来源:https://blog.csdn.net/Mr_Fei/article/details/129044471

目录

一:说明

二:传统鉴权授权的基本配置

三 :角色配置说明

四:策略鉴权授权

五:策略鉴权授权Requirement扩展

总结


一:说明

鉴权:是指验证你是否登录,你登录后的身份是什么。

授权:是指验证你的权限,你的身份有没有权限做这个事。

二:传统鉴权授权的基本配置

Program关键代码:

//表示整个应用程序,调用CreateBuilder方法创建一个WebApplicationBuilder对象。
//初始化当前应用程序的管道容器
using Microsoft.AspNetCore.Authentication.Cookies;var builder = WebApplication.CreateBuilder(args);
//向管道容器添加注册中间件
//添加注册控制器视图中间件
builder.Services.AddControllersWithViews();
//添加注册Session中间件
builder.Services.AddSession();
//添加注册鉴权中间件
builder.Services.AddAuthentication(option =>
{option.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;option.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;option.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;option.DefaultForbidScheme = CookieAuthenticationDefaults.AuthenticationScheme;option.DefaultSignOutScheme = CookieAuthenticationDefaults.AuthenticationScheme;
}).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, option =>
{//鉴权授权失败跳转登录视图option.LoginPath = "/Home/Login";//没有权限跳转指定视图option.AccessDeniedPath = "/Home/NoAuthority";
});
//配置管道容器中间件,构造WebApplication实例
var app = builder.Build();
//判断是否是开发模式
if (!app.Environment.IsDevelopment())
{//向管道中添加中间件,该中间件将捕获异常、记录异常、重置请求路径并重新执行请求。app.UseExceptionHandler("/Shared/Error");//向管道中添加用于使用HSTS的中间件,该中间件添加了Strict Transport Security标头。默认值为30天app.UseHsts();
}
//向管道添加Session中间件
app.UseSession();
//向管道添加用于将HTTP请求重定向到HTTPS的中间件。
app.UseHttpsRedirection();
//向管道添加为当前请求路径启用静态文件服务
app.UseStaticFiles();
//向管道添加路由配置中间件
app.UseRouting();
//向管道添加鉴权中间件
app.UseAuthentication();
//向管道添加授权中间件
app.UseAuthorization();
//向管道添加默认路由中间件
app.MapControllerRoute(name: "default",pattern: "{controller=Home}/{action=Index}/{id?}");
//向管道添加启动应用程序中间件
app.Run();

User关键代码:

using System.ComponentModel.DataAnnotations;namespace Study_ASP.NET_Core_MVC.Models
{public class User{public int UserId { get; set; }[Display(Name="账号")]public string? UserName { get; set; }public string? Account { get; set; }[Display(Name = "密码")]public string? UserPwd { get; set; }[DataType(DataType.EmailAddress)][Display(Name = "邮箱")]public string? UserEmail { get; set;}public DateTime LoginTime { get; set; }}
}

Home控制器代码:

using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Study_ASP.NET_Core_MVC.Models;
using System.Diagnostics;
using System.Security.Claims;namespace Study_ASP.NET_Core_MVC.Controllers
{public class HomeController : Controller{private readonly ILogger<HomeController> _logger;public HomeController(ILogger<HomeController> logger){_logger = logger;}/// <summary>/// Get请求/// 默认授权/// </summary>/// <returns></returns>[HttpGet][Authorize]public IActionResult Index(){var user = HttpContext.User;return View();}/// <summary>/// Get请求/// </summary>/// <returns></returns>public IActionResult NoAuthority(){return View();}/// <summary>/// Get请求/// 登录视图/// </summary>/// <returns></returns>[HttpGet]public IActionResult Login(){return View();}/// <summary>/// Post请求/// 登录视图/// </summary>/// <param name="UserName"></param>/// <param name="UserPwd"></param>/// <returns></returns>[HttpPost]public async Task<IActionResult> Login(string UserName,string UserPwd){if ("VinCente".Equals(UserName) && "123456".Equals(UserPwd)){var claims = new List<Claim>(){new Claim("UserId","1"),new Claim(ClaimTypes.Role,"Admin"),new Claim(ClaimTypes.Role,"User"),new Claim(ClaimTypes.Name,$"{UserName}---来自于Cookies"),new Claim(ClaimTypes.Email,$"VinCente@123.com"),new Claim("Password",UserPwd),new Claim("Account","Administrator"),new Claim("Role","admin"),new Claim("QQ","7257624")};ClaimsPrincipal userPrincipal = new ClaimsPrincipal(new ClaimsIdentity(claims, "UserMessage"));HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, userPrincipal, new AuthenticationProperties{//过期时间30分钟ExpiresUtc = DateTime.UtcNow.AddSeconds(30)}).Wait();var user = HttpContext.User;return base.Redirect("/Home/Index");}else{base.ViewBag.Message = "账号或密码错误";}return await Task.FromResult<IActionResult>(View());}}
}

视图代码:

@using Study_ASP.NET_Core_MVC.Models;@model User
@{ViewBag.Title = "登录";
}<h2>登录</h2>
<div class="row"><div class="col-md-8"><section id="loginForm">@using (Html.BeginForm("Login", "Home", new { sid = "123", Account = "VinCente" },FormMethod.Post, true, new { @class = "form-horizontal", role = "form" })){@Html.AntiForgeryToken()<hr />@Html.ValidationSummary(true)<div class="mb-3 row">@Html.LabelFor(m => m.UserName, new { @class = "col-sm-1 col-form-label" })<div class="col-md-6">@Html.TextBoxFor(m => m.UserName, new { @class = "form-control", @placeholder="请输入账号" })</div></div><div class="mb-3 row">@Html.LabelFor(m => m.UserPwd, new { @class = "col-md-1 control-label" })<div class="col-md-6">@Html.PasswordFor(m => m.UserPwd, new { @class = "form-control",@placeholder="请输入密码" })</div></div><div class="mb-3 row"><div class="col-md-offset-2 col-md-6"><button type="submit" class="btn btn-primary mb-3">登录</button>@base.ViewBag.Message</div></div>}</section></div>
</div> 

三 :角色配置说明

标记多个角色授权控制器代码:

/// <summary>/// Get请求/// 默认授权/// 授权给角色为Admin的用户,可以访问/// 授权给角色为User的用户,可以访问/// 授权给角色为Tracher的用户,不可以访问,VinCente用户没有Teacher授权/// 同时授权给用户多个角色Roles时,必须同时满足角色Roles,才可以访问/// </summary>/// <returns></returns>[HttpGet]//[Authorize][Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme, Roles = "Admin")]//[Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme, Roles = "User")]//[Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme, Roles = "Teacher")]public IActionResult Index(){var user = HttpContext.User;return View();}

标记单个角色授权控制器代码:

/// <summary>/// Get请求/// 默认授权/// 授权给角色为Admin和User的用户,包含其中一个角色,可以访问/// 授权给角色为User和Teacher的用户,包含其中一个角色,可以访问/// 授权给角色为Tracher和Admin的用户,包含其中一个角色,可以访问/// 授权给角色为System和Teacher的用户,不包含其中一个角色,不可以访问/// </summary>/// <returns></returns>[HttpGet]//[Authorize][Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme, Roles = "Admin,User")]//[Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme, Roles = "User,Teacher")]//[Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme, Roles = "Teacher,Admin")]//[Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme, Roles = "System,Teacher")]public IActionResult Index(){var user = HttpContext.User;return View();}

四:策略鉴权授权

Program关键代码:

//表示整个应用程序,调用CreateBuilder方法创建一个WebApplicationBuilder对象。
//初始化当前应用程序的管道容器
using Microsoft.AspNetCore.Authentication.Cookies;
using System.Security.Claims;var builder = WebApplication.CreateBuilder(args);
//向管道容器添加注册中间件
//添加注册控制器视图中间件
builder.Services.AddControllersWithViews();
//添加注册Session中间件
builder.Services.AddSession();
//添加注册鉴权授权中间件
builder.Services.AddAuthentication(option =>
{option.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;option.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;option.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;option.DefaultForbidScheme = CookieAuthenticationDefaults.AuthenticationScheme;option.DefaultSignOutScheme = CookieAuthenticationDefaults.AuthenticationScheme;
}).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, option =>
{//鉴权授权失败跳转登录视图option.LoginPath = "/Home/Login";//没有权限跳转指定视图option.AccessDeniedPath = "/Home/NoAuthority";
});
//添加注册策略鉴权授权中间件
builder.Services.AddAuthorization(option =>
{//注册一个为RolePolicy的策略授权option.AddPolicy("RolePolicy", policyBuilder =>{//必须包含某个角色//policyBuilder.RequireRole("Teacher");//必须包含Account条件//policyBuilder.RequireClaim("Account");//必须包含指定条件policyBuilder.RequireAssertion(context =>{return context.User.HasClaim(c => c.Type == ClaimTypes.Role) && context.User.Claims.First(c => c.Type.Equals(ClaimTypes.Role)).Value == "Admin" && context.User.Claims.Any(c => c.Type == ClaimTypes.Name);});//policyBuilder.AddRequirements(new QQEmailRequirement());});
});
//配置管道容器中间件,构造WebApplication实例
var app = builder.Build();
//判断是否是开发模式
if (!app.Environment.IsDevelopment())
{//向管道中添加中间件,该中间件将捕获异常、记录异常、重置请求路径并重新执行请求。app.UseExceptionHandler("/Shared/Error");//向管道中添加用于使用HSTS的中间件,该中间件添加了Strict Transport Security标头。默认值为30天app.UseHsts();
}
//向管道添加Session中间件
app.UseSession();
//向管道添加用于将HTTP请求重定向到HTTPS的中间件。
app.UseHttpsRedirection();
//向管道添加为当前请求路径启用静态文件服务
app.UseStaticFiles();
//向管道添加路由配置中间件
app.UseRouting();
//向管道添加鉴权中间件
app.UseAuthentication();
//向管道添加授权中间件
app.UseAuthorization();
//向管道添加默认路由中间件
app.MapControllerRoute(name: "default",pattern: "{controller=Home}/{action=Index}/{id?}");
//向管道添加启动应用程序中间件
app.Run();

控制器代码:

using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Study_ASP.NET_Core_MVC.Models;
using System.Diagnostics;
using System.Security.Claims;namespace Study_ASP.NET_Core_MVC.Controllers
{public class HomeController : Controller{private readonly ILogger<HomeController> _logger;public HomeController(ILogger<HomeController> logger){_logger = logger;}/// <summary>/// Get请求/// 策略授权/// </summary>/// <returns></returns>[HttpGet][Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme, Policy = "RolePolicy")]public IActionResult Index(){var user = HttpContext.User;return View();}/// <summary>/// Get请求/// </summary>/// <returns></returns>public IActionResult NoAuthority(){return View();}/// <summary>/// Get请求/// 登录视图/// </summary>/// <returns></returns>[HttpGet]public IActionResult Login(){return View();}/// <summary>/// Post请求/// 登录视图/// </summary>/// <param name="UserName"></param>/// <param name="UserPwd"></param>/// <returns></returns>[HttpPost]public async Task<IActionResult> Login(string UserName, string UserPwd){if ("VinCente".Equals(UserName) && "123456".Equals(UserPwd)){var claims = new List<Claim>(){new Claim("UserId","1"),new Claim(ClaimTypes.Role,"Admin"),new Claim(ClaimTypes.Role,"User"),new Claim(ClaimTypes.Name,$"{UserName}---来自于Cookies"),new Claim(ClaimTypes.Email,$"VinCente@123.com"),new Claim("Password",UserPwd),new Claim("Account","Administrator"),new Claim("Role","admin"),new Claim("QQ","7257624")};ClaimsPrincipal userPrincipal = new ClaimsPrincipal(new ClaimsIdentity(claims, "UserMessage"));HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, userPrincipal, new AuthenticationProperties{//过期时间30分钟ExpiresUtc = DateTime.UtcNow.AddSeconds(30)}).Wait();var user = HttpContext.User;return base.Redirect("/Home/Index");}else{base.ViewBag.Message = "账号或密码错误";}return await Task.FromResult<IActionResult>(View());}}
}

五:策略鉴权授权Requirement扩展

IUserService代码:

namespace Study_ASP.NET_Core_MVC.Models
{public interface IUserService{public bool Validata(string userId, string qq);}
}

UserService代码:

namespace Study_ASP.NET_Core_MVC.Models
{public class UserService: IUserService{public bool Validata(string userId, string qq){//在这里去链接数据库去校验这个QQ是否正确return true;}}
}

QQEmailRequirement代码:

using Microsoft.AspNetCore.Authorization;namespace Study_ASP.NET_Core_MVC.Models
{public class QQEmailRequirement:IAuthorizationRequirement{}
}

QQHandler代码:

using Microsoft.AspNetCore.Authorization;namespace Study_ASP.NET_Core_MVC.Models
{public class QQHandler:AuthorizationHandler<QQEmailRequirement>{//初始化构造函数private IUserService _UserService;public QQHandler(IUserService userService){this._UserService = userService;}protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, QQEmailRequirement requirement){if (context.User.Claims.Count() == 0){return Task.CompletedTask;}string userId = context.User.Claims.First(c => c.Type == "UserId").Value;string qq = context.User.Claims.First(c => c.Type == "QQ").Value;if (_UserService.Validata(userId, qq)){//验证通过context.Succeed(requirement);}return Task.CompletedTask;}}
}

Program关键代码:

//表示整个应用程序,调用CreateBuilder方法创建一个WebApplicationBuilder对象。
//初始化当前应用程序的管道容器
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Study_ASP.NET_Core_MVC.Models;
using System.Security.Claims;var builder = WebApplication.CreateBuilder(args);
//向管道容器添加注册中间件
//添加注册控制器视图中间件
builder.Services.AddControllersWithViews();
//添加注册Session中间件
builder.Services.AddSession();
//添加注册鉴权授权中间件
builder.Services.AddAuthentication(option =>
{option.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;option.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;option.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;option.DefaultForbidScheme = CookieAuthenticationDefaults.AuthenticationScheme;option.DefaultSignOutScheme = CookieAuthenticationDefaults.AuthenticationScheme;
}).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, option =>
{//鉴权授权失败跳转登录视图option.LoginPath = "/Home/Login";//没有权限跳转指定视图option.AccessDeniedPath = "/Home/NoAuthority";
});
//添加注册策略鉴权授权中间件
builder.Services.AddAuthorization(option =>
{//注册一个为RolePolicy的策略授权option.AddPolicy("RolePolicy", policyBuilder =>{//必须包含某个角色//policyBuilder.RequireRole("Teacher");//必须包含Account条件//policyBuilder.RequireClaim("Account");//必须包含指定条件policyBuilder.RequireAssertion(context =>{return context.User.HasClaim(c => c.Type == ClaimTypes.Role) && context.User.Claims.First(c => c.Type.Equals(ClaimTypes.Role)).Value == "Admin" && context.User.Claims.Any(c => c.Type == ClaimTypes.Name);});policyBuilder.AddRequirements(new QQEmailRequirement());});
});
//添加注册策略鉴权授权中间件外部文件
builder.Services.AddTransient<IUserService, UserService>();
builder.Services.AddTransient<IAuthorizationHandler, QQHandler>();
//配置管道容器中间件,构造WebApplication实例
var app = builder.Build();
//判断是否是开发模式
if (!app.Environment.IsDevelopment())
{//向管道中添加中间件,该中间件将捕获异常、记录异常、重置请求路径并重新执行请求。app.UseExceptionHandler("/Shared/Error");//向管道中添加用于使用HSTS的中间件,该中间件添加了Strict Transport Security标头。默认值为30天app.UseHsts();
}
//向管道添加Session中间件
app.UseSession();
//向管道添加用于将HTTP请求重定向到HTTPS的中间件。
app.UseHttpsRedirection();
//向管道添加为当前请求路径启用静态文件服务
app.UseStaticFiles();
//向管道添加路由配置中间件
app.UseRouting();
//向管道添加鉴权中间件
app.UseAuthentication();
//向管道添加授权中间件
app.UseAuthorization();
//向管道添加默认路由中间件
app.MapControllerRoute(name: "default",pattern: "{controller=Home}/{action=Index}/{id?}");
//向管道添加启动应用程序中间件
app.Run();

控制器代码:

using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Study_ASP.NET_Core_MVC.Models;
using System.Diagnostics;
using System.Security.Claims;namespace Study_ASP.NET_Core_MVC.Controllers
{public class HomeController : Controller{private readonly ILogger<HomeController> _logger;public HomeController(ILogger<HomeController> logger){_logger = logger;}/// <summary>/// Get请求/// 策略授权/// </summary>/// <returns></returns>[HttpGet][Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme, Policy = "RolePolicy")]public IActionResult Index(){var user = HttpContext.User;return View();}/// <summary>/// Get请求/// </summary>/// <returns></returns>public IActionResult NoAuthority(){return View();}/// <summary>/// Get请求/// 登录视图/// </summary>/// <returns></returns>[HttpGet]public IActionResult Login(){return View();}/// <summary>/// Post请求/// 登录视图/// </summary>/// <param name="UserName"></param>/// <param name="UserPwd"></param>/// <returns></returns>[HttpPost]public async Task<IActionResult> Login(string UserName, string UserPwd){if ("VinCente".Equals(UserName) && "123456".Equals(UserPwd)){var claims = new List<Claim>(){new Claim("UserId","1"),new Claim(ClaimTypes.Role,"Admin"),new Claim(ClaimTypes.Role,"User"),new Claim(ClaimTypes.Name,$"{UserName}---来自于Cookies"),new Claim(ClaimTypes.Email,$"VinCente@123.com"),new Claim("Password",UserPwd),new Claim("Account","Administrator"),new Claim("Role","admin"),new Claim("QQ","7257624")};ClaimsPrincipal userPrincipal = new ClaimsPrincipal(new ClaimsIdentity(claims, "UserMessage"));HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, userPrincipal, new AuthenticationProperties{//过期时间30分钟ExpiresUtc = DateTime.UtcNow.AddSeconds(30)}).Wait();var user = HttpContext.User;return base.Redirect("/Home/Index");}else{base.ViewBag.Message = "账号或密码错误";}return await Task.FromResult<IActionResult>(View());}}
}

总结

        使用传统鉴权授权的基本配置,验证用户是否登录,如果当前没有用户信息直接跳转至登录视图,在Program文件中配置,登录之后可以正常访问被标记为[Authorize]的控制器或控制器方法,由于控制器代码中HttpPost的Login方法中写明用户角色。搭配角色使用,在控制器或控制器方法上标记可以访问该控制器或方法的角色,除了当前标记的角色外,都不可以访问该控制器或控制器方法。搭配策略使用,在特殊的控制器或控制器上标记可以访问该控制器或方法的策略名称,符合该策略的用户可以访问。不能访问的用户直接跳转至Home控制器下的NoAuthority方法中的视图,提醒用户没有权限访问该方法。通过使用AddRequirements扩展,可以自定义验证用户鉴权授权。

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

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

相关文章

【vue2每日小知识】实现store中modules模块的封装与自动导入

&#x1f973;博 主&#xff1a;初映CY的前说(前端领域) &#x1f31e;个人信条&#xff1a;想要变成得到&#xff0c;中间还有做到&#xff01; &#x1f918;本文核心&#xff1a;省去我们store仓库中分模块时的需要每次导入index的问题 目录 【前言】在store中如何简…

ELK日志分析--Filebeat

ELK架构 Filebeat简介 Filebeat安装 Filebeat简单使用 专用日志搜集模块 案例模块-Nginx 模块 重读日志文件 使用Processors(处理器)过滤和增强数据 1.ELK架构 2.Filebeat简介 可以使用 Filebeat 收集各种日志&#xff0c;之后发送到指定的目标系统上&#xff0c;但是同…

软件测试面试题 —— 整理与解析(1)

&#x1f60f;作者简介&#xff1a;博主是一位测试管理者&#xff0c;同时也是一名对外企业兼职讲师。 &#x1f4e1;主页地址&#xff1a;&#x1f30e;【Austin_zhai】&#x1f30f; &#x1f646;目的与景愿&#xff1a;旨在于能帮助更多的测试行业人员提升软硬技能&#xf…

【华为OD机试真题】用 C++ 实现 - 数字加减游戏

最近更新的博客 华为OD机试 - 入栈出栈(C++) | 附带编码思路 【2023】 华为OD机试 - 箱子之形摆放(C++) | 附带编码思路 【2023】 华为OD机试 - 简易内存池 2(C++) | 附带编码思路 【2023】 华为OD机试 - 第 N 个排列(C++) | 附带编码思路 【2023】 华为OD机试 - 考古…

程序员如何发展第二职业?这几种副业方式超赚钱

很多程序员曾表示&#xff0c;虽然月薪一两万&#xff0c;但有时候还是会焦虑。 尤其是遇上了年初裁员年底裁员这样的就业环境&#xff0c;焦虑就会逐步放大&#xff0c;这时候副业赚钱的重要性就体现出来了。 发展第二职业&#xff0c;可以让程序员们增加抗风险能力&#xf…

数据结构-考研难点代码突破(树型查找 - 红黑树(RBT)插入流程图,删除)

文章目录1. 红黑树的定义和性质红黑树的插入操作流程红黑树的删除&#xff08;了解&#xff09;1. 红黑树的定义和性质 红黑树查找与删除的效率和AVL树相同。 但是因为AVL树在插入或删除节点可能破坏AVL树结构&#xff0c;而重新调整树的开销大。所以引出了红黑树。 红黑树的…

【Jmeter】ForEach控制器

一、什么是ForEach控制器 ForEach控制器是遍历某个数组读取不同的变量值&#xff0c;来控制其下的采样器或控制器执行一次或多次。而这个数组可以是用户自定义变量&#xff0c;也可以是从前面接口请求中提取到需要的数据&#xff0c;然后进行遍历循环。 二、ForEach控制器相关…

技能提升:Python技术应用工程师职业技能提升

职业技术培训-Python技术应用工程师分为高级培训班、中级培训班及初级培训班。 Python是一种跨平台的计算机程序设计语言&#xff0c;是一个高层次的结合了解释性、编译性、互动性和面向对象的语言。最初被设计用于编写自动化脚本Shell&#xff08;适用于Linux操作系统&#xf…

Linux PWM 开发指南

Linux PWM 开发指南 1 概述 1.1 编写目的 介绍 PWM 模块的详细设计方便相关人员进行 PWM 模块的代码设计开发。 1.2 使用范围 适用于 Linux-3.10&#xff0c;linux-4.4 和 Linux-4.9 内核&#xff0c;Linux-5.4 内核。 1.3 相关人员 PWM 驱动的开发人员/维护人员等 2 术…

数据库系统概论——绪论

1、绪论 1.1、数据库系统概述 数据库系统的构成示意图 1.1.1、数据库系统基本概念 基本概念&#xff1a;数据、数据库、数据库管理系统和数据库系统 1&#xff09;数据&#xff08;data&#xff09; 定义&#xff1a;描述事物的符号记录称为数据数据是数据库中存储的基本对象…

中科检测赴中科院广州电子CASAIM开展座谈会,围绕3D打印、三维扫描和精密测量展开深入交流

2月9日&#xff0c;中科检测技术服务(广州)股份有限公司&#xff08;简称&#xff1a;中科检测&#xff09;一行到访中科院广州电子技术有限公司&#xff0c;参观广东省增材制造工程实验室和三维扫描及精密测量重点实验室&#xff0c;就3D打印、三维扫描和精密测量相关技术内容…

NTP同步时钟为医院提供标准的时间信号

NTP同步时钟应用于城市重要公共领域&#xff0c;如车站、学校、医院、等。NTP同步时钟可提供准确的公众时间&#xff0c;为人们的日常生活提供便利&#xff0c;避免了因时钟不准确而带来的不便。NTP同步时钟采用智能模块化设计&#xff0c;与同类产品相比&#xff0c;更突出了安…

JavaScript Web API实战:7个小众技巧让你的网站瞬间提升用户体验

随着技术的日新月异&#xff0c;为开发人员提供了令人难以置信的新工具和API。但据了解&#xff0c;在100 多个 API中&#xff0c;只有5%被开发人员积极使用。 让我们来看看一些有用的Web API&#xff0c;它们可以帮助您将网站推向月球&#xff01; 1、 截屏接口 Screen Capt…

ELK日志分析--Logstash

Logstash简介 Logstash安装 测试运行 配置输入和输出 使用Geoip过滤器插件增强数据编辑 配置接收 Beats 的输入 1.Logstash简介 Logstash管道具有两个必需元素input和output&#xff0c;以及一个可选元素filter。输入插件使用来自源的数据&#xff0c;过滤器插件根据你的…

shell的测试语句

一、shell的条件测试语句 在写shell脚本时&#xff0c;经常遇到的问题就是判断字符串是否相等&#xff0c;可能还要检查文件状态或进 行数字测试&#xff0c;只有这些测试完成才能做下一步动作。 1.1、shell脚本中的条件测试如下&#xff1a; 1、文件测试 2、字符串测试 3、数…

《计算机组成与系统结构(第二版) 裘雪红 李伯成 西安电子科技大学出版社》课后习题答案(带解析)(三)

声明&#xff1a;此系列答案配套《计算机组成与系统结构&#xff08;第二版&#xff09; 裘雪红 李伯成 西安电子科技大学出版社》一书相关内容。所有内容为博主个人编辑&#xff0c;仅作参考学习交流之用&#xff0c;转载请注明出处。如发现错误&#xff0c;请联系博主及时勘误…

java JMM 内存屏障

内存屏障的目的 每个CPU都会有自己的缓存&#xff08;有的甚至L1,L2,L3&#xff09;&#xff0c;缓存的目的就是为了提高性能&#xff0c;避免每次都要向内存取。但是这样的弊端也很明显&#xff1a;不能实时的和内存发生信息交换&#xff0c;分在不同CPU执行的不同线程对同一…

基于SPI的增强式插件框架设计

很久之前&#xff0c;为了诊断线上的问题&#xff0c;就想要是能有工具可以在线上出问题的时候&#xff0c;放个诊断包进去马上生效&#xff0c;就能看到线上问题的所在&#xff0c;那该是多么舒服的事情。后来慢慢的切换到 java 领域后&#xff0c;这种理想也变成了现实&#…

【selenium 自动化测试】如何搭建自动化测试环境,搭建环境过程应该注意的问题

最近也有很多人私下问我&#xff0c;selenium学习难吗&#xff0c;基础入门的学习内容很多是3以前的版本资料&#xff0c;对于有基础的人来说&#xff0c;3到4的差别虽然有&#xff0c;但是不足以影响自己&#xff0c;但是对于没有学过的人来说&#xff0c;通过资料再到自己写的…

2023年PMP考试应该注意些什么?

首先注意&#xff08;报考条件&#xff09; 2023年PMP考试报名流程&#xff1a; 一、PMP英文报名&#xff1a; 英文报名时间无限制&#xff0c;随时可以报名&#xff0c;但有一年的有效期&#xff0c;所以大家尽量提前报名&#xff0c;在英文报名有效期内进行中文报名。 英…