PHP之hyperf学习笔记
Hyperf
Model,Dao,Service,Contronller
路由
- 使用文件来配置路由,就是和laravel一样的
Router::addGroup(["middleware" => ["web", "auth"],"namespace" => "Hyperf\HttpServer\Controller","prefix" => "hyperf",
],function (Router $router){Router::get("/", "Hyperf\Hyperf\Controller\IndexController@index");
});
- 使用注解去配置路由
#[Controller(“prefix”)]
#[AutoController(“prefix”)]
#[RequestMapping(path:‘index’,method:“get,post”)]
#[GetMapping(path:“index”)]
依赖注入
- DI依赖注入
- IOC控制反转
- #[Inject]
- private UserService $user;
- 所有的DI都是单列模式的
- /config/dependencies.php 就是可以配置接口类和工厂类的关系
- //接口::class => 实体类::class 这样就可以注入接口的时候就是自动转化为实体类进行注入 会去调用实体类的public function __invoke 方法
- DI创建出来的都是单例,都是唯一的,会被所有的协程去使用
AOP
- 被切入的类必须要是DI管理的,要使用AOP必须要切入,直接new是不行的
- 定义一个切面 文件夹Aspect创建一个切面类 继承AbstractAspect
- 这个是切面的函数
<?php
namespace App\Aspect;use App\Service\SomeClass;
use App\Annotation\SomeAnnotation;
use Hyperf\Di\Annotation\Aspect;
use Hyperf\Di\Aop\AbstractAspect;
use Hyperf\Di\Aop\ProceedingJoinPoint;#[Aspect]
class FooAspect extends AbstractAspect
{// 要切入的类或 Trait,可以多个,亦可通过 :: 标识到具体的某个方法,通过 * 可以模糊匹配//定义要切入的类 public array $classes = [SomeClass::class,'App\Service\SomeClass::someMethod','App\Service\SomeClass::*Method',];// 要切入的注解,具体切入的还是使用了这些注解的类,仅可切入类注解和类方法注解public array $annotations = [SomeAnnotation::class,];public function process(ProceedingJoinPoint $proceedingJoinPoint){// 切面切入后,执行对应的方法会由此来负责// $proceedingJoinPoint 为连接点,通过该类的 process() 方法调用原方法并获得结果// 在调用前进行某些处理$result = $proceedingJoinPoint->process();// 在调用后进行某些处理return $result;}
}
- 直接使用注解配置来达到和上面一样的目的
<?php
namespace App\Aspect;use App\Service\SomeClass;
use App\Annotation\SomeAnnotation;
use Hyperf\Di\Annotation\Aspect;
use Hyperf\Di\Aop\AbstractAspect;
use Hyperf\Di\Aop\ProceedingJoinPoint;#[Aspect(classes: [SomeClass::class,"App\Service\SomeClass::someMethod","App\Service\SomeClass::*Method"],annotations: [SomeAnnotation::class])
]
class FooAspect extends AbstractAspect
{public function process(ProceedingJoinPoint $proceedingJoinPoint){// 切面切入后,执行对应的方法会由此来负责// $proceedingJoinPoint 为连接点,通过该类的 process() 方法调用原方法并获得结果// 在调用前进行某些处理$result = $proceedingJoinPoint->process();// 在调用后进行某些处理return $result;}
}
- 在aspect中获取一些需要的参数 以更灵活的实现aspect
<?php
namespace App\Aspect;use App\Service\SomeClass;
use App\Annotation\SomeAnnotation;
use Hyperf\Di\Annotation\Aspect;
use Hyperf\Di\Aop\AbstractAspect;
use Hyperf\Di\Aop\ProceedingJoinPoint;#[Aspect]
class FooAspect extends AbstractAspect
{public array $classes = [SomeClass::class,'App\Service\SomeClass::someMethod','App\Service\SomeClass::*Method',];public array $annotations = [SomeAnnotation::class,];public function process(ProceedingJoinPoint $proceedingJoinPoint){// 获取当前方法反射原型/** @var \ReflectionMethod **/$reflect = $proceedingJoinPoint->getReflectMethod();// 获取调用方法时提交的参数$arguments = $proceedingJoinPoint->getArguments(); // array// 获取原类的实例并调用原类的其他方法$originalInstance = $proceedingJoinPoint->getInstance();$originalInstance->yourFunction();// 获取注解元数据/** @var \Hyperf\Di\Aop\AnnotationMetadata **/$metadata = $proceedingJoinPoint->getAnnotationMetadata();// 调用不受代理类影响的原方法$proceedingJoinPoint->processOriginalMethod();// 不执行原方法,做其他操作$result = date('YmdHis', time() - 86400);return $result;}
}
- 代理类缓存 config/config.php scan_cacheable
注解
- 没搞清楚使用在哪里 下次在来
事件机制
- 这个有点像是队列的意思
- 其实就是为了解耦
- 定义一个事件 这个事件来了就是要做一些其他的操作 用户注册事件,用户注册完之后可能要做一些其他的事情,比如发送邮箱什么的
- 定义一个事件
<?php
namespace App\Event;class UserRegistered
{// 建议这里定义成 public 属性,以便监听器对该属性的直接使用,或者你提供该属性的 Getterpublic $user;public function __construct($user){$this->user = $user; }
}
- 定义一个监听器
<?php
namespace App\Listener;use App\Event\UserRegistered;
use Hyperf\Event\Contract\ListenerInterface;class UserRegisteredListener implements ListenerInterface
{public function listen(): array{// 返回一个该监听器要监听的事件数组,可以同时监听多个事件return [UserRegistered::class,];}/*** @param UserRegistered $event*/public function process(object $event): void{// 事件触发后该监听器要执行的代码写在这里,比如该示例下的发送用户注册成功短信等// 直接访问 $event 的 user 属性获得事件触发时传递的参数值// $event->user;}
}
- 去配置监听器 让这个监听器在监听
- config/autoload/listeners.php
<?php
return [\App\Listener\UserRegisteredListener::class,
];
- 通过注解去实现监听器
<?php
namespace App\Listener;use App\Event\UserRegistered;
use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;#[Listener]
class UserRegisteredListener implements ListenerInterface
{public function listen(): array{// 返回一个该监听器要监听的事件数组,可以同时监听多个事件return [UserRegistered::class,];}/*** @param UserRegistered $event*/public function process(object $event): void{// 事件触发后该监听器要执行的代码写在这里,比如该示例下的发送用户注册成功短信等// 直接访问 $event 的 user 属性获得事件触发时传递的参数值// $event->user;}
}
在通过注解注册监听器时,我们可以通过设置 priority 属性定义当前监听器的顺序,如 #[Listener(priority=1)] ,底层使用 SplPriorityQueue 结构储存,priority 数字越大优先级越高
- 对监听器的一个使用
<?php
namespace App\Service;use Hyperf\Di\Annotation\Inject;
use Psr\EventDispatcher\EventDispatcherInterface;
use App\Event\UserRegistered; class UserService
{#[Inject]private EventDispatcherInterface $eventDispatcher;public function register(){// 我们假设存在 User 这个实体$user = new User();$result = $user->save();// 完成账号注册的逻辑// 这里 dispatch(object $event) 会逐个运行监听该事件的监听器$this->eventDispatcher->dispatch(new UserRegistered($user));return $result;}
}
中间件
- config/autoload/middlewares.php 全局中间件
<?php
return [// http 对应 config/autoload/server.php 内每个 server 的 name 属性对应的值,该配置仅应用在该 Server 中'http' => [// 数组内配置您的全局中间件,顺序根据该数组的顺序YourMiddleware::class],
];
- 使用注解的方式 #[Middleware(FooMiddleware::class)]
- 多个中间件 #[Middleware([FooMiddleware::class,barMiddleware::class])]
- 生成中间件 php ./bin/hyperf.php gen:middleware Auth/FooMiddleware
<?phpdeclare(strict_types=1);namespace App\Middleware\Auth;use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface as HttpResponse;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;class FooMiddleware implements MiddlewareInterface
{protected ContainerInterface $container;protected RequestInterface $request;protected HttpResponse $response;public function __construct(ContainerInterface $container, HttpResponse $response, RequestInterface $request){$this->container = $container;$this->response = $response;$this->request = $request;}public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface{// 根据具体业务判断逻辑走向,这里假设用户携带的token有效$isValidToken = true;if ($isValidToken) {return $handler->handle($request);}return $this->response->json(['code' => -1,'data' => ['error' => '中间件验证token无效,阻止继续向下执行',],]);}
}
- 中间件的执行顺序
// 全局中间件配置文件 middleware.php
return ['http' => [YourMiddleware::class,YourMiddlewareB::class => 3,],
];
- 中间件的注解方式
// 注解中间件配置
#[AutoController]
#[Middleware(FooMiddleware::class)]
#[Middleware(FooMiddlewareB::class, 3)]
#[Middlewares([FooMiddlewareC::class => 1, BarMiddlewareD::class => 4])]
class IndexController
{}
- 如果要在中间件中修改$request那么需要使用功能Context去改变
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;// $request 和 $response 为修改后的对象
$request = \Hyperf\Context\Context::set(ServerRequestInterface::class, $request);
$response = \Hyperf\Context\Context::set(ResponseInterface::class, $response);
- 默认情况下在处理路由的时候,找不到或者什么都是执行CoreMiddleware 可以重写这个方法
- 跨域中间件 hyperf官网有
请求Request
- 在hyperf中一般注入的都是RequestInterface
- 常用方法的集合
$request->path();
$request->url();
$request->fullUrl();
$request->getMethod();
$request->all();
$request->input("name",'most');
// 存在则返回,不存在则返回 null
$name = $request->query('name');
// 存在则返回,不存在则返回默认值 Hyperf
$name = $request->query('name', 'Hyperf');
// 不传递参数则以关联数组的形式返回所有 Query 参数
$name = $request->query();
$request->has('name');
$request->cookie('name');
// 存在则返回一个 Hyperf\HttpMessage\Upload\UploadedFile 对象,不存在则返回 null
$file = $request->file('photo');
if ($request->hasFile('photo')) {// ...
}
if ($request->file('photo')->isValid()) {// ...
}
// 该路径为上传文件的临时路径
$path = $request->file('photo')->getPath();// 由于 Swoole 上传文件的 tmp_name 并没有保持文件原名,所以这个方法已重写为获取原文件名的后缀名
$extension = $request->file('photo')->getExtension();
$file = $request->file('photo');
$file->moveTo('/foo/bar.jpg');// 通过 isMoved(): bool 方法判断方法是否已移动
if ($file->isMoved()) {// ...
}
响应Responce
- r e s p o n s e − > j s o n ( response->json( response−>json(data);
- r e s p o n s e − > x m l ( response->xml( response−>xml(data);
- $response->raw(‘Hello Hyperf.’);
- 还有问价下载的方法具体看文档
控制器
- 实现interface接口类
异常
<?php
namespace App\Exception\Handler;use Hyperf\ExceptionHandler\ExceptionHandler;
use Hyperf\HttpMessage\Stream\SwooleStream;
use Psr\Http\Message\ResponseInterface;
use App\Exception\FooException;
use Throwable;
class FooExceptionHandler extends ExceptionHandler
{public function handle(Throwable $throwable, ResponseInterface $response){// 判断被捕获到的异常是希望被捕获的异常if ($throwable instanceof FooException) {// 格式化输出$data = json_encode(['code' => $throwable->getCode(),'message' => $throwable->getMessage(),], JSON_UNESCAPED_UNICODE);// 阻止异常冒泡$this->stopPropagation();return $response->withStatus(500)->withBody(new SwooleStream($data));}// 交给下一个异常处理器return $response;// 或者不做处理直接屏蔽异常}/*** 判断该异常处理器是否要对该异常进行处理*/public function isValid(Throwable $throwable): bool{return true;}
}
缓存
- SimpleCache
$cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
- 这文档缓存讲的不太行
日志
- 就这样的吧 讲的也不太行
分页器
- 没啥好讲的 默认是自动读取page的
- UserModel::paginate(10)
自动化测试
- 模拟http请求
<?php
use Hyperf\Testing\Client;
$client = make(Client::class);
$result = $client->get('/');
验证器
- 全局验证器 在server.php 中配置
<?php
return [// 下面的 http 字符串对应 config/autoload/server.php 内每个 server 的 name 属性对应的值,意味着对应的中间件配置仅应用在该 Server 中'http' => [// 数组内配置您的全局中间件,顺序根据该数组的顺序\Hyperf\Validation\Middleware\ValidationMiddleware::class// 这里隐藏了其它中间件],
];
- 使用方式
- 1.创建一个验证器
php bin/hyperf.php gen:request FooRequest
- 2.编写规则
/*** 获取应用到请求的验证规则*/
public function rules(): array
{return ['foo' => 'required|max:255','bar' => 'required',];
}
-3. 使用
<?php
namespace App\Controller;use App\Request\FooRequest;class IndexController
{public function index(FooRequest $request){// 传入的请求通过验证...// 获取通过验证的数据...$validated = $request->validated();}
}
- 可以添加一个自定义的异常类来处理这个文件
- 验证规则要去看
数据库模型
- 执行原生sql
<?php
use Hyperf\DbConnection\Db;
$users = Db::select('SELECT * FROM `user` WHERE gender = ?',[1]); // 返回array
foreach($users as $user){echo $user->name;
}
//执行类
<?phpuse Hyperf\DbConnection\Db;$inserted = Db::insert('INSERT INTO user (id, name) VALUES (?, ?)', [1, 'Hyperf']); // 返回是否成功 bool$affected = Db::update('UPDATE user set name = ? WHERE id = ?', ['John', 1]); // 返回受影响的行数 int$affected = Db::delete('DELETE FROM user WHERE id = ?', [1]); // 返回受影响的行数 int$result = Db::statement("CALL pro_test(?, '?')", [1, 'your words']); // 返回 bool CALL pro_test(?,?) 为存储过程,属性为 MODIFIES SQL DATA
- 事务
use Hyperf\DbConnection\Db;Db::beginTransaction();
try{// Do something...Db::commit();
} catch(\Throwable $ex){Db::rollBack();
}
- 打印最后一条sql
// 打印最后一条 SQL 相关数据
var_dump(Arr::last(Db::getQueryLog()));
- 获取的多个值是Collection 获取的单个值是stdClass
- 获取第一条 ->first()
- 获取第一列值 ->pluck(‘name’) 也可以多个 ->p
- 获取单个值 ->value(“id”)
- 查询指定字段 ->select(‘id’,‘name’,‘gender’)
- Or
$users = Db::table('user')->where('gender', 1)->orWhere('name', 'John')->get();
- whereBetween
$users = Db::table('users')->whereBetween('votes', [1, 100])->get();
模型
- 创建模型 php ./bin/hyper.php gen:model table_name
- 时间戳
<?php
declare(strict_types=1);
namespace App\Model;
use Hyperf\DbConnection\Model\Model;
class User extends Model
{public bool $timestamps = false;
}
- 保护属性 f i l l a b l e 可填充, fillable 可填充, fillable可填充,guarded 保护属性
- 配置软删除
<?php
namespace App\Model;
use Hyperf\Database\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
class User extends Model
{use SoftDeletes;
}
模型关系
- 一对一 User有一个Role
<?php
declare(strict_types=1);
namespace App\Models;
use Hyperf\DbConnection\Model\Model;
class User extends Model
{public function role(){第一个参数 one的类,User表中的外键 主键 一对一是主表需要有外键 当然谁都可以成为主表return $this->hasOne(Role::class, 'user_id', 'id');}
}
- 一对多 User有多个Book
<?phpdeclare(strict_types=1);namespace App\Models;use Hyperf\DbConnection\Model\Model;class User extends Model
{public function books(){return $this->hasMany(Book::class, 'user_id', 'id');}
}
- 一对多反向 属于关系
<?phpdeclare(strict_types=1);namespace App\Models;use Hyperf\DbConnection\Model\Model;class Book extends Model
{public function author(){//参数永远都是外键 然后主键return $this->belongsTo(User::class, 'user_id', 'id');}
}
- 多对多
- 假设User表和Role
- 前置条件 role_id user_id 中间表 role_user
<?phpnamespace App;use Hyperf\DbConnection\Model\Model;class User extends Model
{public function roles(){外表,中间表,自己的的外键,外键 记住这个顺序 基本都是按这个顺序来的return $this->belongsToMany(Role::class, 'role_user', 'user_id', 'role_id');//return $this->belongsToMany(Role::class);}
}
- 获取中间表字段
$user = User::find(1);foreach ($user->roles as $role) {echo $role->pivot->created_at;
}
- 如果需要其他字段需要在关联的时候指出
return $this->belongsToMany(Role::class)->withPivot('column1', 'column2');
访问器&修改器
- 访问器
<?phpnamespace App;use Hyperf\DbConnection\Model\Model;class User extends Model
{/*** 获取用户的姓名.** @param string $value* @return string*/public function getFirstNameAttribute($value){return ucfirst($value);}
}
- 修改器
<?phpnamespace App;use Hyperf\DbConnection\Model\Model;class User extends Model
{/*** 设置用户的姓名.** @param string $value* @return void*/public function setFirstNameAttribute($value){$this->attributes['first_name'] = strtolower($value);}
}相关文章:
PHP之hyperf学习笔记
Hyperf Model,Dao,Service,Contronller 路由 使用文件来配置路由,就是和laravel一样的 Router::addGroup(["middleware" > ["web", "auth"],"namespace" > "Hyperf\HttpServer\Contr…...
react的antd表格数据回显在form表单中
1、首先为table添加编辑按钮 {title: 操作,align: center,render: (_: any, record: any) > (<div style{{ display: flex, alignItems: center, justifyContent: space-evenly }}><Buttonsize"small"onClick{() > deitor(record)} style{{ margin…...
【通俗易懂说模型】线性回归(附深度学习、机器学习发展史)
🌈 个人主页:十二月的猫-CSDN博客 🔥 系列专栏: 🏀深度学习_十二月的猫的博客-CSDN博客 💪🏻 十二月的寒冬阻挡不了春天的脚步,十二点的黑夜遮蔽不住黎明的曙光 目录 1. 前言 2. …...
【R语言】apply函数族
在R语言中使用循环操作时是使用自身来实现的,效率较低。所以R语言有一个符合其统计语言出身的特点:向量化。R语言中的向量化运用了底层的C语言,而C语言的效率比高层的R语言的效率高。 apply函数族主要是为了解决数据向量化运算的问题&#x…...
传统营销架构在当下如何进行优化转型?
随着市场环境的变化和数字技术的发展,传统营销架构越来越难以适应当下的营销市场。为了适应新时代的要求,企业也需要对营销架构进行优化转型。企业主可以着手从哪些方面进行调整呢?下面就来一同探讨下。 一、强调扁平化原则 扁平化与去中心化…...
QMK启用摇杆和鼠标按键功能
虽然选择了触摸屏,我仍选择为机械键盘嵌入摇杆模块,这本质上是对"操作连续性"的执着。 值得深思的是,本次开发过程中借助DeepSeek的代码生成与逻辑推理,其展现的能力已然颠覆传统编程范式,需求描述可自动…...
计算机网络-SSH基本原理
最近年底都在忙,然后这两天好点抽空更新一下。前面基本把常见的VPN都学习了一遍,后面的内容应该又继续深入一点。 一、SSH简介 SSH(Secure Shell,安全外壳协议)是一种用于在不安全网络上进行安全远程登录和实现其他安…...
yolov11模型在Android设备上运行【踩坑记录】
0) 参考资料: https://github.com/Tencent/ncnn?tabreadme-ov-file https://github.com/pnnx/pnnx https://github.com/nihui/ncnn-android-yolov5 https://github.com/Tencent/ncnn?tabreadme-ov-file 1) :将xxx.pt模型转化成 xxx.onnx ONNX(Ope…...
Linux在x86环境下制作ARM镜像包
在x86环境下制作ARM镜像包(如qemu.docker),可以通过QEMU和Docker的结合来实现。以下是详细的步骤: 安装QEMU-user-static QEMU-user-static是一个静态编译的QEMU二进制文件,用于在非目标架构上运行目标架构的二进制文…...
win编译openssl
一、perl执行脚本 1、安装perl脚本 perl安装 2、配置perl脚本 perl Configure VC-WIN32 no-asm no-shared --prefixE:\openssl-x.x.x\install二、编译openssl 1、使用vs工具编译nmake 如果使用命令行nmake编译会提示“无法打开包括文件: “limits.h”“ 等错误信息 所以…...
为什么说,在IT行业中长期从事外包岗位没有前途?
文章目录 前言一、职业发展与技能提升受限二、工作稳定性和归属感缺失三、薪资待遇和福利差异四、行业声誉和求职歧视总结 前言 在IT行业中,由于企业要降低成本、优化资源、分散风险以及满足市场需求和技术需求等原因,存在大量的外包岗位。很多人都说长…...
【B站保姆级视频教程:Jetson配置YOLOv11环境(七)Ultralytics YOLOv11配置】
Jetson配置YOLOv11环境(7)Ultralytics YOLOv11环境配置 文章目录 1. 下载YOLOv11 github项目2. 安装ultralytics包3. 验证ultralytics安装3.1 下载yolo11n.pt权重文件3.2 推理 1. 下载YOLOv11 github项目 创建一个目录,用于存放YOLOv11的项目…...
硬核技术:小程序能够调用手机的哪些传感器
一、加速度传感器 小程序可以调用手机的加速度传感器来检测设备的运动状态。加速度传感器能够测量设备在三个轴(X、Y、Z)上的加速度变化。通过分析这些数据,小程序可以实现一些功能,如运动检测、步数统计、游戏中的动作感应等。 健…...
Day 31 卡玛笔记
这是基于代码随想录的每日打卡 491. 非递减子序列 给你一个整数数组 nums ,找出并返回所有该数组中不同的递增子序列,递增子序列中 至少有两个元素 。你可以按 任意顺序 返回答案。 数组中可能含有重复元素,如出现两个整数相等࿰…...
【蓝桥杯嵌入式】4_key:单击+长按+双击
全部代码网盘自取 链接:https://pan.baidu.com/s/1PX2NCQxnADxYBQx5CsOgPA?pwd3ii2 提取码:3ii2 1、电路图 将4个按键的引脚设置为input,并将初始状态设置为Pull-up(上拉输入) 为解决按键抖动的问题,我们…...
Synchronized和ReentrantLock面试详解
前言 接下来为大家带来的是 Java 中的两个典型锁代表:Synchronized 和 ReentrantLock 的详解 面试题:谈一谈AQS 在说 ReentrantLock 时,有必要先了解一下 AQS,因为 ReentrantLock 就是基于 AQS 实现的 分析: 共享…...
1.2 学习驱动(Driver)分为几步?
文章目录 前言一、什么是UVM中的驱动(Driver)?二、如何理解Driver?三、如何使用Driver?第一步:定义Driver类第二步:实现run_phase任务第三步:实现驱动任务第四步:实例化和…...
【MySQL篇】事务的认识以及四大特性
何为事务? 事务(Transaction)是指一组操作的集合,这些操作要么全部执行成功,要么全部不执行。事务通常用于保证数据库的一致性、完整性和可靠性,确保数据的完整性与正确性。 有效避免部分执行,…...
2.7日学习总结
深入探究栈、队列与二叉树 一、栈的深度剖析 进阶特性:除了常规的入栈、出栈操作,栈在处理函数调用、表达式求值等场景时,展现出独特的递归模拟能力。利用栈可以将递归算法转化为非递归形式,有效避免因递归过深导致的栈溢出问题。…...
SQL带外注入
SQL 带外注入(Out-of-Band SQL Injection, OOB SQLi) 是 SQL 注入的一种特殊类型,主要用于以下情况: 数据库没有直接返回错误信息(比如被防火墙拦截了)。无法使用常规注入手法(如 UNION、错误信…...
Nginx进阶篇 - nginx多进程架构详解
文章目录 1. nginx的应用特点2. nginx多进程架构2.1 nginx多进程模型2.2 master进程的作用2.3 进程控制2.4 worker进程的作用2.5 worker进程处理请求的过程2.6 nginx处理网络事件 1. nginx的应用特点 Nginx是互联网企业使用最为广泛的轻量级高性能Web服务器,其特点是…...
【算法专场】分治(下)
目录 前言 归并排序 思想 912. 排序数组 算法思路 算法代码 LCR 170. 交易逆序对的总数 算法思路 算法代码 315. 计算右侧小于当前元素的个数 - 力扣(LeetCode) 算法思路 算法代码 493. 翻转对 算法思路 算法代码 好久不见~时隔多日&…...
OSPF基础(2):数据包详解
OSPF数据包(可抓包) OSPF报文直接封装在IP报文中,协议号89 头部数据包内容: 版本(Version):对于OSPFv2,该字段值恒为2(使用在IPV4中);对于OSPFv3,该字段值恒为3(使用在IPV6中)。类型(Message Type):该OSPF报文的类型。…...
ubuntu直接运行arm环境qemu-arm-static
qemu-arm-static 嵌入式开发有时会在ARM设备上使用ubuntu文件系统。开发者常常会面临这样一个问题,想预先交叉编译并安装一些应用程序,但是交叉编译的环境配置以及依赖包的安装十分繁琐,并且容易出错。想直接在目标板上进行编译和安装&#x…...
Docker Desktop安装kubernetes时一直在Starting:Kubernetes failed to start
原因:由于墙的问题,导致拉取国外的K8s镜像失败 解决: 下载 k8s-for-docker-desktop 选中自己的kubernetes 版本 下载zip包 PowerShell运行load_images.ps1文件 重启docker kubernetes运行成功...
beyond the ‘PHYSICAL‘ memory limit.问题处理
Container [pid5616,containerIDcontainer_e50_1734408743176_3027740_01_000006] is running 507887616B beyond the ‘PHYSICAL’ memory limit. Current usage: 4.5 GB of 4 GB physical memory used; 6.6 GB of 8.4 GB virtual memory used. Killing container. 1.增大map…...
AI大模型零基础学习(1):大模型使用篇
一、大模型是什么?为什么你需要它? 一句话理解:大模型像一个能听懂人话的"超级智能助手",它能写文章、解数学题、翻译语言、写代码…只要你会打字提问,它就能给出答案。 典型场景: 学生党&…...
StarSpider 星蛛 爬虫 Java框架 可以实现 lazy爬取 实现 HTML 文件的编译,子标签缓存等操作
StarSpider 星蛛 爬虫 Java框架 开源技术栏 StarSpider 能够实现 针对 HTML XSS SQL 数学表达式等杂乱数据的 爬取 解析 提取 需求! 目录 文章目录 StarSpider 星蛛 爬虫 Java框架目录介绍如何获取?maven配置 架构是什么样的?结果对象的类…...
【翻译+论文阅读】DeepSeek-R1评测:粉碎GPT-4和Claude 3.5的开源AI革命
目录 一、DeepSeek-R1 势不可挡二、DeepSeek-R1 卓越之处三、DeepSeek-R1 创新设计四、DeepSeek-R1 进化之路1. 强化学习RL代替监督微调学习SFL2. Aha Moment “啊哈”时刻3. 蒸馏版本仅采用SFT4. 未来研究计划 部分内容有拓展,部分内容有删除,与原文会有…...
先进制造aps专题二十八 生产排程仿真引擎和工厂生产仿真引擎的设计
一 排产仿真引擎的设计 主要分为仿真模型,仿真模型逻辑和仿真框架这三个部分 1 仿真模型 和算法排产不一样,在算法排产里,机器对应的是数据库记录,排产逻辑是写在整体的算法里的,而仿真排产,机器对应的是…...
