当前位置: 首页 > news >正文

hyperf 十九 数据库 二 模型

教程:Hyperf

一、命令行

symfony/console-CSDN博客

hypery 十一、命令行-CSDN博客

hyperf console 执行-CSDN博客

根据之前应该能了解到命令行的基本实现,和hyperf中命令行的定义。

1.1 命令初始化

hyperf.php中系统初始化中通过ApplicationFactory::__invoke(),将配置文件中的commands对应内容,通过Application::add($container->get($command)),设置为Application::command参数的值,类型为数组。

以ModelCommand::configure()为例,通过Hyperf\Config\ProviderConfig::load()进行配置加载,其作用就是将ModelCommand之类的命令类实例化,并设置为ProviderConfig::providerConfigs的值。

实例化的过程中,调用顺序为:

        1、Hyperf\Database\Commands\ModelCommand::__construct()

        2、Hyperf\Command\Command::__construct()

        3、Symfony\Component\Console\Command::__construct()

        4、$this->configure();

 

1.2 调用命令

执行命令通过Symfony\Component\Console\Application::run(),其中总过Application::get()获取Application::command中对应命令的尸体类。

Application::run()会调用Application::doRunCommand(),doRunCommand()中执行对应命令的run()方法。

实际运行以ModelCommand::handle()为例,调用顺序为:

        1、Hyperf\Database\Commands\ModelCommand::run()

        2、Hyperf\Command\Command::run()

        3、Symfony\Component\Console\Command\Command::run()

        4、Hyperf\Command\Command::execute()

        5、Hyperf\Database\Commands\ModelCommand::handle()

1.3 ModelCommand执行

命令执行的入口为ModelCommand::handle(),通过设置参数,获取可处理数据。

若设置table则执行createModel(),否者执行createModels()。createModels()通过循环调用createModel()。

参数中ignore-tables,可设置需要忽略的表,在createModels()中起作用。

参数pool、inheritance、uses,替换对应/stubs/Model.stub文件中的内容。

参数path、prefix、table-mapping,则影响model文件生成。

和文档中不同的参数包括:with-ide、visitors

with-ide:是否生成对应mode的ide文件

visitors:设置ModelUpdateVisitor、ModelRewriteConnectionVisitor之类,用于处理数据的类。可用文件在vendor\hyperf\database\src\Commands\Ast中。可参考:创建脚本 - Hyperf 帮助文档 v2.0 - 开发文档 - 文江博客

二、参数设置

命令行

php bin/hyperf.php gen:model table_name

参数

参数类型默认值备注
--poolstringdefault连接池,脚本会根据当前连接池配置创建
--pathstringapp/Model模型路径
--force-castsboolfalse是否强制重置 casts 参数
--prefixstring空字符串表前缀
--inheritancestringModel父类
--usesstringHyperf\DbConnection\Model\Model配合 inheritance 使用
--refresh-fillableboolfalse是否刷新 fillable 参数
--table-mappingarray[]为表名 -> 模型增加映射关系 比如 ['users:Account']
--ignore-tablesarray[]不需要生成模型的表名 比如 ['users']
--with-commentsboolfalse是否增加字段注释
--property-caseint0字段类型 0 蛇形 1 驼峰

可以通过命令行设置参数,可也在设置中写入参数。

设置中参数设置:

#config\autoload\databases.php
use Hyperf\Database\Commands\ModelOption;return ['default' => [// 忽略其他配置'commands' => ['gen:model' => ['path' => 'app/Model','force_casts' => true,'inheritance' => 'Model','uses' => '','refresh_fillable' => true,'table_mapping' => [],'with_comments' => true,'property_case' => ModelOption::PROPERTY_SNAKE_CASE,],],],
];

 命令中设置参数的时候,通过ModelCommand::getOption(),会将命令行ArgvInput()::getOption(),通过判断是否使用配置中的参数

根据代码,参数中force-casts、refresh-fillable、with-comments、with-ide,若命令行中未传且配置中已设置,则会使用配置中的值。参数中table-mapping、ignore-tables、visitors都为数组,若命令行中未传且配置中已设置,则会使用配置中的值。即配置参数以命令行中参数优先使用

三、测试

3.1 配置

hyperf.php配置

 'commands' => ['gen:model' => ['path' => 'app1/Model','force_casts' => true,'inheritance' => 'Model',],
],

 mysql:

CREATE TABLE `userinfo` (`id` int(11) NOT NULL AUTO_INCREMENT,`name` varchar(255) DEFAULT NULL,`age` tinyint(2) DEFAULT '0',PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=22 DEFAULT CHARSET=utf8;

 composer.json

 "autoload": {"psr-4": {"App\\": "app/","App1\\":"app1/"},"files": []},

3.2 创建

php bin/hyperf.php gen:model --table-mapping='userinfo:User' --prefix=app1 userinfo

执行挺简单一句, 没想到坑还挺多。

首先因为使用的是app1,而非app,所以在composer.json中增加psr-4,因为框架会循环psr-4中的值,根据逻辑判断返回对应的$path,没有匹配的数据则抛出throw。

composer.json修改之后需要composer update。否则对于以上情况,第一次生成model之后,再次处理对应model会报model找不到。

最后发现的一个坑,是文档上写明table-mapping应该是数组,写法应该是["userinfo:User"]。但是特别奇葩的是,创建过程中,将值格式化为["[userinfo"=>"User]"]……后来发现,table-mapping获取的值都是字符串和输入的格式无关,但是之后getTableMapping()没有对字符串进行处理,仅是分割字符串。可能和版本有关,或者因为我输入的格式有误。

还有一个可能是编译器导致的错误,创建的时候有个框架里的文件报错,里面的使用的部分类找不到。原因是没有设置对应的use,但是框架里对应文件存在,补充use语句之后bug解决。

3.3 插入

#model
class User extends Model
{public $timestamps = false;
}#测试
class TestController extends AbstractController
{public function testmodel(){$name = $this->request->input('name');$m_u = new User();$m_u->name = (string) $name;$result = $m_u->save();var_dump($result);}
}#执行结果
true

数据库配置文件在config/autoload/databases.php,但是里面设置的默认值只有在.env中对应值未设置的时候才生效。所以已有.env时,应该再检查下该文件数据库配置是否有误。

默认使用created_at,updated_at字段,设置$timestamps = false后关闭。

3.4 查询

$user = User::query()->where('id', 1)->first();
var_dump($user->name, $user->age);#运行结果
string(3) "123"
int(22)

3.5 软删除

#model
use Hyperf\DbConnection\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
/***/
class User extends Model
{use SoftDeletes;
}#测试代码
$result = User::query()->where(['id' => 23])->delete();
var_dump($result);#测试结果
int(1)

 软删除必须在数据中设置deleted_at字段。

四、源码

4.1 ModelCommand执行

namespace Hyperf\Database\Commands;
class ModelCommand extends Command
{public function handle(){$table = $this->input->getArgument('table');$pool = $this->input->getOption('pool');$option = new ModelOption();$option->setPool($pool)->setPath($this->getOption('path', 'commands.gen:model.path', $pool, 'app/Model'))->setPrefix($this->getOption('prefix', 'prefix', $pool, ''))->setInheritance($this->getOption('inheritance', 'commands.gen:model.inheritance', $pool, 'Model'))->setUses($this->getOption('uses', 'commands.gen:model.uses', $pool, 'Hyperf\DbConnection\Model\Model'))->setForceCasts($this->getOption('force-casts', 'commands.gen:model.force_casts', $pool, false))->setRefreshFillable($this->getOption('refresh-fillable', 'commands.gen:model.refresh_fillable', $pool, false))->setTableMapping($this->getOption('table-mapping', 'commands.gen:model.table_mapping', $pool, []))->setIgnoreTables($this->getOption('ignore-tables', 'commands.gen:model.ignore_tables', $pool, []))->setWithComments($this->getOption('with-comments', 'commands.gen:model.with_comments', $pool, false))->setWithIde($this->getOption('with-ide', 'commands.gen:model.with_ide', $pool, false))->setVisitors($this->getOption('visitors', 'commands.gen:model.visitors', $pool, []))->setPropertyCase($this->getOption('property-case', 'commands.gen:model.property_case', $pool));if ($table) {$this->createModel($table, $option);} else {$this->createModels($option);}}protected function createModel(string $table, ModelOption $option){$builder = $this->getSchemaBuilder($option->getPool());$table = Str::replaceFirst($option->getPrefix(), '', $table);$columns = $this->formatColumns($builder->getColumnTypeListing($table));$project = new Project();$class = $option->getTableMapping()[$table] ?? Str::studly(Str::singular($table));$class = $project->namespace($option->getPath()) . $class;$path = BASE_PATH . '/' . $project->path($class);if (!file_exists($path)) {$this->mkdir($path);file_put_contents($path, $this->buildClass($table, $class, $option));}$columns = $this->getColumns($class, $columns, $option->isForceCasts());$stms = $this->astParser->parse(file_get_contents($path));$traverser = new NodeTraverser();$traverser->addVisitor(make(ModelUpdateVisitor::class, ['class' => $class,'columns' => $columns,'option' => $option,]));$traverser->addVisitor(make(ModelRewriteConnectionVisitor::class, [$class, $option->getPool()]));$data = make(ModelData::class)->setClass($class)->setColumns($columns);foreach ($option->getVisitors() as $visitorClass) {$traverser->addVisitor(make($visitorClass, [$option, $data]));}$stms = $traverser->traverse($stms);$code = $this->printer->prettyPrintFile($stms);file_put_contents($path, $code);$this->output->writeln(sprintf('<info>Model %s was created.</info>', $class));if ($option->isWithIde()) {$this->generateIDE($code, $option, $data);}}
protected function createModels(ModelOption $option){$builder = $this->getSchemaBuilder($option->getPool());$tables = [];foreach ($builder->getAllTables() as $row) {$row = (array) $row;$table = reset($row);if (!$this->isIgnoreTable($table, $option)) {$tables[] = $table;}}foreach ($tables as $table) {$this->createModel($table, $option);}}protected function isIgnoreTable(string $table, ModelOption $option): bool{if (in_array($table, $option->getIgnoreTables())) {return true;}return $table === $this->config->get('databases.migrations', 'migrations');}
}
namespace Hyperf\Utils\CodeGen;
class Project
{public function namespace(string $path): string{$ext = pathinfo($path, PATHINFO_EXTENSION);if ($ext !== '') {$path = substr($path, 0, -(strlen($ext) + 1));} else {$path = trim($path, '/') . '/';}foreach ($this->getAutoloadRules() as $prefix => $prefixPath) {if ($this->isRootNamespace($prefix) || strpos($path, $prefixPath) === 0) {return $prefix . str_replace('/', '\\', substr($path, strlen($prefixPath)));}}throw new \RuntimeException("Invalid project path: {$path}");}protected function getAutoloadRules(): array{return data_get(Composer::getJsonContent(), 'autoload.psr-4', []);}
}
namespace Hyperf\Database\Commands;
class ModelOption
{public function setTableMapping(array $tableMapping): self{foreach ($tableMapping as $item) {[$key, $name] = explode(':', $item);$this->tableMapping[$key] = $name;}return $this;}
}

4.2 $timestamps使用

namespace Hyperf\Database\Model;
abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializable, CompressInterface
{use Concerns\HasTimestamps;public function save(array $options = []): bool{$this->mergeAttributesFromClassCasts();$query = $this->newModelQuery();// If the "saving" event returns false we'll bail out of the save and return// false, indicating that the save failed. This provides a chance for any// listeners to cancel save operations if validations fail or whatever.if ($saving = $this->fireModelEvent('saving')) {if ($saving instanceof StoppableEventInterface && $saving->isPropagationStopped()) {return false;}}// If the model already exists in the database we can just update our record// that is already in this database using the current IDs in this "where"// clause to only update this model. Otherwise, we'll just insert them.if ($this->exists) {$saved = $this->isDirty() ? $this->performUpdate($query) : true;} else {// If the model is brand new, we'll insert it into our database and set the// ID attribute on the model to the value of the newly inserted row's ID// which is typically an auto-increment value managed by the database.$saved = $this->performInsert($query);if (! $this->getConnectionName() && $connection = $query->getConnection()) {$this->setConnection($connection->getName());}}// If the model is successfully saved, we need to do a few more things once// that is done. We will call the "saved" method here to run any actions// we need to happen after a model gets successfully saved right here.if ($saved) {$this->finishSave($options);}return $saved;}protected function performUpdate(Builder $query){// If the updating event returns false, we will cancel the update operation so// developers can hook Validation systems into their models and cancel this// operation if the model does not pass validation. Otherwise, we update.if ($event = $this->fireModelEvent('updating')) {if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {return false;}}// First we need to create a fresh query instance and touch the creation and// update timestamp on the model which are maintained by us for developer// convenience. Then we will just continue saving the model instances.if ($this->usesTimestamps()) {$this->updateTimestamps();}// Once we have run the update operation, we will fire the "updated" event for// this model instance. This will allow developers to hook into these after// models are updated, giving them a chance to do any special processing.$dirty = $this->getDirty();if (count($dirty) > 0) {$this->setKeysForSaveQuery($query)->update($dirty);$this->syncChanges();$this->fireModelEvent('updated');}return true;}
}

4.4 SoftDeletes使用

namespace Hyperf\Database\Model;
abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializable, CompressInterface
{public function delete(){$this->mergeAttributesFromClassCasts();if (is_null($this->getKeyName())) {throw new Exception('No primary key defined on model.');}// If the model doesn't exist, there is nothing to delete so we'll just return// immediately and not do anything else. Otherwise, we will continue with a// deletion process on the model, firing the proper events, and so forth.if (! $this->exists) {return;}if ($event = $this->fireModelEvent('deleting')) {if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {return false;}}// Here, we'll touch the owning models, verifying these timestamps get updated// for the models. This will allow any caching to get broken on the parents// by the timestamp. Then we will go ahead and delete the model instance.$this->touchOwners();$this->performDeleteOnModel();// Once the model has been deleted, we will fire off the deleted event so that// the developers may hook into post-delete operations. We will then return// a boolean true as the delete is presumably successful on the database.$this->fireModelEvent('deleted');return true;}
}
namespace App1\Model;use Hyperf\Database\Model\SoftDeletes;
/***/
class User extends Model
{use SoftDeletes;
}
namespace Hyperf\Database\Model;
trait SoftDeletes
{protected function performDeleteOnModel(){if ($this->forceDeleting) {$this->exists = false;return $this->newModelQuery()->where($this->getKeyName(), $this->getKey())->forceDelete();}return $this->runSoftDelete();}protected function runSoftDelete(){$query = $this->newModelQuery()->where($this->getKeyName(), $this->getKey());$time = $this->freshTimestamp();$columns = [$this->getDeletedAtColumn() => $this->fromDateTime($time)];$this->{$this->getDeletedAtColumn()} = $time;if ($this->timestamps && ! is_null($this->getUpdatedAtColumn())) {$this->{$this->getUpdatedAtColumn()} = $time;$columns[$this->getUpdatedAtColumn()] = $this->fromDateTime($time);}$query->update($columns);}public function getDeletedAtColumn(){return defined('static::DELETED_AT') ? static::DELETED_AT : 'deleted_at';}
}

相关文章:

hyperf 十九 数据库 二 模型

教程&#xff1a;Hyperf 一、命令行 symfony/console-CSDN博客 hypery 十一、命令行-CSDN博客 hyperf console 执行-CSDN博客 根据之前应该能了解到命令行的基本实现&#xff0c;和hyperf中命令行的定义。 1.1 命令初始化 hyperf.php中系统初始化中通过ApplicationFacto…...

使用python快速开发与PDF文档对话的Gemini聊天机器人

检索增强生成(Retrieval-augmented generation&#xff0c;RAG)使得我们可以让大型语言模型(LLMs)访问外部知识库数据(如pdf,word、text等)&#xff0c;从而让人们可以更加方便的通过LLM来学习外部数据的知识。今天我们将利用之前学习到的RAG方法&#xff0c;谷歌Gemini模型和l…...

Spring Cloud Gateway集成Knife4j

1、前提 网关路由能够正常工作。 案例 基于 Spring Cloud Gateway Nacos 实现动态路由拓展的参考地址&#xff1a;Spring Cloud Gateway Nacos 实现动态路由 详细官网案例&#xff1a;https://doc.xiaominfo.com/docs/middleware-sources/spring-cloud-gateway/spring-gatewa…...

Hive10_窗口函数

窗口函数&#xff08;开窗函数&#xff09; 1 相关函数说明 普通的聚合函数聚合的行集是组,开窗函数聚合的行集是窗口。因此,普通的聚合函数每组(Group by)只返回一个值&#xff0c;而开窗函数则可为窗口中的每行都返回一个值。简单理解&#xff0c;就是对查询的结果多出一列…...

ipvsadm命令详解

ipvsadm命令详解 大家好&#xff0c;我是免费搭建查券返利机器人赚佣金就用微赚淘客系统3.0的小编&#xff0c;也是冬天不穿秋裤&#xff0c;天冷也要风度的程序猿&#xff01;今天我们将深入探讨一个在Linux系统网络管理中极具威力的命令——ipvsadm&#xff0c;通过详细解析…...

zabbix通过自动发现-配置监控项、触发器(小白教程)

自动发现配置参考链接&#xff08;不小白&#xff0c;不友好&#xff09; zabbix-get介绍 1配置 zabbix server&#xff1a;版本7&#xff08;不影响&#xff09;,IP地址&#xff1a;192.168.0.60zabbix agent&#xff1a;版本agent1&#xff08;不影响&#xff09;&#xff…...

Dockerfile文件介绍

0 Preface/Foreword 0.1 Docker docker用来自制镜像。 1 Introduction 1.1 Dockerfile Dockerfile是用于定义Docker镜像的构建过程&#xff0c;它包含一系列的指令用于安装 软件包、配置环境等操作。 Dockerfile文件的格式如下&#xff1a; FROM base_image RUN apt-get up…...

【PHP】函数array_reduce()使用场景

目录 1.计算数组中所有元素的和 2.计算数组中所有元素的乘积 3.将多个字符串连接在一起 4.对数组中的元素进行逻辑计算 5.取出第一个满足条件的数组&#xff0c;筛选有用数组 6.array_reduce()函数的基本语法&#xff1a; array_reduce 函数通常用于对数组中的元素进行累…...

软件测试基础理论学习-软件测试方法论

软件测试方法论 软件测试的方法应该建立在不同的软件测试类型上&#xff0c;不同的测试类型会存在不同的方法。本文以软件测试中常见的黑盒测试为例&#xff0c;简述常见软件测试方法。 黑盒测试用例设计方法包括等价类划分法、边界值分析法、因果图法、判定表驱动法、正交试…...

Unity 关于点击不同物品移动并触发不同事件

关于点击不同物品触发不同事件 可以实现在界面中点击不同的物体&#xff0c;移动到物品附近位置&#xff0c;然后触发对应的事件。 首先建立一个公共管理的类&#xff1a; public class InteractionObject : MonoBehaviour {private NavMeshAgent PlayerAgent;private bool …...

c++IO库详细介绍

文章目录 前言c IO 类简介1. iostream库iostream 类标准IO对象 2. fstream库fstream 类 3. stringstream库stringstream 类 格式化和控制错误处理 IO对象无拷贝或赋值IO条件状态主要的状态标志检查流状态控制流状态示例 管理输出缓冲主要操作示例 文件输入输出使用文件流对象示…...

海外静态IP和动态IP有什么区别?推荐哪种?

什么是静态ip、动态ip&#xff0c;二者有什么区别&#xff1f;哪种好&#xff1f;关于这个问题&#xff0c;不难发现&#xff0c;在知道、知乎上面的解释有很多&#xff0c;但据小编的发现&#xff0c;这些回答都是关于静态ip和动态ip的专业术语解释&#xff0c;普通非专业人事…...

OpenHarmony从入门到放弃(一)

OpenHarmony从入门到放弃&#xff08;二&#xff09; 一、OpenHarmony的基本概念和特性 OpenHarmony是由开放原子开源基金会孵化及运营的开源项目&#xff0c;其目标是构建一个面向全场景、全连接、全智能的时代的智能终端设备操作系统。 分布式架构 OpenHarmony采用分布式…...

Unity3D UGUI图集打包与动态使用(TexturePacker)

制作图集的好处&#xff1a; 众所周知CPU是用来处理游戏的逻辑运算的&#xff0c;而GPU是用来处理游戏中图像的。在GPU中&#xff0c;我们要绘制一个图像需要提交图片&#xff08;纹理&#xff09;到显存&#xff0c;然后再进行绘制&#xff08;在这个过程中会产生一次DrawCall…...

java maven项目添加oracle jdbc的依赖

一般添加依赖是直接在pom.xml中添加配置即可&#xff0c;Maven会自动获取对应的jar包&#xff0c;但是oracle驱动依赖添加后会显示红色&#xff0c;代表找不到依赖项&#xff0c;是因为Oracle授权问题&#xff0c;Maven3不提供Oracle JDBC driver&#xff0c;为了在Maven项目中…...

【UEFI基础】EDK网络框架(环境配置)

环境配置 为了能够让使用测试BIOS的QEMU与主机&#xff08;就是指普通的Windows系统&#xff0c;我们使用它来编译BIOS和启动QEMU虚拟机&#xff09;通过网络连接&#xff0c;需要额外的配置。 首先是下载和安装OpenVPN&#xff08;这里安装的是OpenVPN-2.5.5-I601-amd64.msi…...

K8S学习指南(60)-K8S源代码走读之API-Server

文章目录 API Server 的代码结构API Server 的核心逻辑1. 请求处理流程1.1 HTTP 请求处理1.2 认证和授权1.3 API 版本处理1.4 资源路由1.5 资源处理1.6 响应生成 2. 存储层2.1 存储接口定义2.2 存储实现 二次开发扩展点1. 插件机制1.1 插件注册1.2 插件实现 2. 自定义资源定义&…...

基于深度学习的交通标志图像分类识别系统

温馨提示&#xff1a;文末有 CSDN 平台官方提供的学长 QQ 名片 :) 1. 项目简介 本文详细探讨了一基于深度学习的交通标志图像识别系统。采用TensorFlow和Keras框架&#xff0c;利用卷积神经网络&#xff08;CNN&#xff09;进行模型训练和预测&#xff0c;并引入VGG16迁移学习…...

使用uni-app editor富文本组件设置富文本内容及解决@Ready先于onload执行,无法获取后端接口数据的问题

开始使用富文本组件editor时&#xff0c;不知如何调用相关API设置富文本内容和获取内容&#xff0c;本文将举例详解 目录 一.了解editor组件的常用属性及相关API 1.属性常用说明 2.富文本相关API说明 1&#xff09;editorContext 2&#xff09; editorContext.setContents…...

Spring高手之路-Spring事务的传播机制(行为、特性)

目录 含义 七种事务传播机制 1.REQUIRED&#xff08;默认&#xff09; 2.REQUIRES_NEW 3.SUPPORTS 4.NOT_SUPPORTED 5.MANDATORY 6.NEVER 7.NESTED 含义 Spring事务的传播机制是指在多个事务方法相互调用时&#xff0c;如何处理这些事务的传播行为。对应七种事务传播行为…...

Vue记事本应用实现教程

文章目录 1. 项目介绍2. 开发环境准备3. 设计应用界面4. 创建Vue实例和数据模型5. 实现记事本功能5.1 添加新记事项5.2 删除记事项5.3 清空所有记事 6. 添加样式7. 功能扩展&#xff1a;显示创建时间8. 功能扩展&#xff1a;记事项搜索9. 完整代码10. Vue知识点解析10.1 数据绑…...

docker详细操作--未完待续

docker介绍 docker官网: Docker&#xff1a;加速容器应用程序开发 harbor官网&#xff1a;Harbor - Harbor 中文 使用docker加速器: Docker镜像极速下载服务 - 毫秒镜像 是什么 Docker 是一种开源的容器化平台&#xff0c;用于将应用程序及其依赖项&#xff08;如库、运行时环…...

<6>-MySQL表的增删查改

目录 一&#xff0c;create&#xff08;创建表&#xff09; 二&#xff0c;retrieve&#xff08;查询表&#xff09; 1&#xff0c;select列 2&#xff0c;where条件 三&#xff0c;update&#xff08;更新表&#xff09; 四&#xff0c;delete&#xff08;删除表&#xf…...

React第五十七节 Router中RouterProvider使用详解及注意事项

前言 在 React Router v6.4 中&#xff0c;RouterProvider 是一个核心组件&#xff0c;用于提供基于数据路由&#xff08;data routers&#xff09;的新型路由方案。 它替代了传统的 <BrowserRouter>&#xff0c;支持更强大的数据加载和操作功能&#xff08;如 loader 和…...

Swift 协议扩展精进之路:解决 CoreData 托管实体子类的类型不匹配问题(下)

概述 在 Swift 开发语言中&#xff0c;各位秃头小码农们可以充分利用语法本身所带来的便利去劈荆斩棘。我们还可以恣意利用泛型、协议关联类型和协议扩展来进一步简化和优化我们复杂的代码需求。 不过&#xff0c;在涉及到多个子类派生于基类进行多态模拟的场景下&#xff0c;…...

自然语言处理——Transformer

自然语言处理——Transformer 自注意力机制多头注意力机制Transformer 虽然循环神经网络可以对具有序列特性的数据非常有效&#xff0c;它能挖掘数据中的时序信息以及语义信息&#xff0c;但是它有一个很大的缺陷——很难并行化。 我们可以考虑用CNN来替代RNN&#xff0c;但是…...

OpenLayers 分屏对比(地图联动)

注&#xff1a;当前使用的是 ol 5.3.0 版本&#xff0c;天地图使用的key请到天地图官网申请&#xff0c;并替换为自己的key 地图分屏对比在WebGIS开发中是很常见的功能&#xff0c;和卷帘图层不一样的是&#xff0c;分屏对比是在各个地图中添加相同或者不同的图层进行对比查看。…...

Maven 概述、安装、配置、仓库、私服详解

目录 1、Maven 概述 1.1 Maven 的定义 1.2 Maven 解决的问题 1.3 Maven 的核心特性与优势 2、Maven 安装 2.1 下载 Maven 2.2 安装配置 Maven 2.3 测试安装 2.4 修改 Maven 本地仓库的默认路径 3、Maven 配置 3.1 配置本地仓库 3.2 配置 JDK 3.3 IDEA 配置本地 Ma…...

08. C#入门系列【类的基本概念】:开启编程世界的奇妙冒险

C#入门系列【类的基本概念】&#xff1a;开启编程世界的奇妙冒险 嘿&#xff0c;各位编程小白探险家&#xff01;欢迎来到 C# 的奇幻大陆&#xff01;今天咱们要深入探索这片大陆上至关重要的 “建筑”—— 类&#xff01;别害怕&#xff0c;跟着我&#xff0c;保准让你轻松搞…...

C++课设:简易日历程序(支持传统节假日 + 二十四节气 + 个人纪念日管理)

名人说:路漫漫其修远兮,吾将上下而求索。—— 屈原《离骚》 创作者:Code_流苏(CSDN)(一个喜欢古诗词和编程的Coder😊) 专栏介绍:《编程项目实战》 目录 一、为什么要开发一个日历程序?1. 深入理解时间算法2. 练习面向对象设计3. 学习数据结构应用二、核心算法深度解析…...