Kotlin Basic

Kotlin注解

  1. Deprecated:如果需要废弃一个方法,只需要在方法钱加上 @Deprecated 即可。
  2. Suppress:如果需要消除一些编译时的警告,可以使用 @Suppress(“xxx”) 。
  3. Volatile:为了强制变量中的更改立即对其他线程可见,我们可以使用注解 @Volatile。
  4. Synchronized:Java 有 synchronized 关键字,可以将其应用于方法以确保一次只有一个线程可以访问它们。进入同步方法的线程获得锁(被锁定的对象是包含类的实例),并且在释放锁之前没有其他线程可以进入该方法。Kotlin通过 @Synchronized 注解提供了相同的功能。
  5. Bindable:数据绑定有两种与数据交互的基本方式:BaseObservable 类及其关联的 @Bindable 注释,以及 LiveData 可观察包装器(LiveData observable wrapper)。
  6. RequiresApi:需要调用一些之前版本的API,比如需要调用API 26,Android 8 (Oreo),即,在函数的上一行加上 @RequiresApi(Build.VERSION_CODES.O) 即可。
  7. SerializedName:通常使用@SerializedName批注来映射JSON字段。

巧用Kotlin:内置函数let、also、with、run、apply大大提高你的开发效率!

  1. let:定义一个变量在一个特定作用域,使其在作用域内可使用,(统一)避免一个判空操作。返回值 = 最后一行 / return的表达式。
  2. aslo:与let类似,区别在于:返回值 = 传入的对象的本身。
  3. with:调用同一个对象的多个方法 / 属性时,可以省去对象名重复,直接调用方法名 / 属性即可,返回值 = 函数块的最后一行 / return表达式。
  4. run:结合了let、with两个函数的作用,返回值 = 函数块的最后一行 / return表达式。
  5. apply:与run函数类似,但区别在于返回值,apply函数返回传入的对象的本身。
  • 总结:
    Kotlin函数

.NET hotel manager system code study

来自:https://gitee.com/dacom/hotel-management-system 的大聪/酒店管理系统。

安装过程

  1. VS2022+SQLServer2012。
  2. 数据库直接附加,注意设置文件权限。
  3. 错误:

4.

Laravel Filament Notes

Laravel Filament 使用流水笔记。


[2024-06-12] Select组件通过relationship关联列表

  1. 在编辑表中定义BelongsTo字段,关联到提供列表的表Model。
    1
    2
    3
    4
     public function category(): BelongsTo
    {
    return $this->belongsTo(Category::class, 'category_id', 'id');
    }
  2. 再定义Select组件,使用relationship方法关联进来
    1
    2
    Forms\Components\Select::make('category_id') 
    ->relationship('category', 'name'),
  • 可以通过getOptionLabelFromRecordUsing方法将显示值进行自定义。

[2024-06-12] Select(或Radio)组件的值必须是键名-键值对

  • Select组件指定的值,即使显示值和保存值相同,也必须设置数组的键名-键值对,否则无法正常显示(可能获取到了默认数字键名0,1…无法匹配)
    1
    2
    3
    4
    5
    Forms\Components\Select::make('Country')->options([
    '英国' => '英国',
    '美国' => '美国',
    '德国' => '德国'
    ])

[2024-06-11] Filament中的Tabs

  • Tab::make($name)->label($label),创建时make中的$name参数必须是规范的组件名,而不是标题(显示标题通过label函数指定),指定中文等不规范的命名将导致页面异常并且不可点击。
  • Forms\Components\Section组件则是相反的,它的label()方法并不起作用,标题必须作为make()方法的参数传入。

[2024-01-18] Filament.Table头部按钮

1
2
3
4
$table->headerActions([
ExportAction::make(),
... //创建Action数组
], HeaderActionsPosition::Bottom) //指定对方方式,Bottom为左对齐

[2024-01-18] 创建一个弹出ModalDialog的Action

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Tables\Actions\Action::make('sync')
->label(__('Sync'))
->form([
//创建一个选择框
Forms\Components\Select::make('channel_id')
->label(__('Shop'))
->required()
->options(Shop::all()->pluck('Title', 'ChannelId'))
])
->modalWidth(MaxWidth::Small) //指定对话框大小
->action(function (Table $table, array $data) {
//alert($data['channel_id']);
$filter = $table->getFilter('shop');
$filter->modifyQueryUsing(fn (Builder $query) => $query->where(["ChannelId" => $data["channel_id"]])
);

[2024-01-19] 在form中添加按钮

  • 在form中可用的Components并没有按钮组件,而要创建Action并调用->button()实现;

  • 但是,form()方法只接受Forms\Components\组件的数组,直接添加Action实例是不允许的;

  • 正确的做法是,创建一个Actions,并向make方法的参数传入一个数组,在该数组中创建Action:

    1
    2
    3
    4
    5
    6
    7
    8
    9

    ->form([
    ... //其它组件
    Forms\Components\Actions::make([
    Forms\Components\Actions\Action::make('Generate excerpt')
    ->action(function (array $data): void {
    //执行操作
    })
        ])

Git Command Guide

GIT命令行指引

您还可以按照以下说明从计算机中上传现有文件。

Git 全局设置

1
2
git config --global user.name "Cable Home"
git config --global user.email "cablefan@hotmail.com"

创建一个新仓库

1
2
3
4
5
6
7
git clone http://{old-domain}/private/mybanks.git
cd mybanks
git switch -c main
touch README.md
git add README.md
git commit -m "add README"
git push -u origin main

推送现有文件夹

1
2
3
4
5
6
cd existing_folder
git init --initial-branch=main
git remote add origin http://`{old-domain}`/private/mybanks.git
git add .
git commit -m "Initial commit"
git push -u origin main

推送现有的 Git 仓库

1
2
3
4
5
cd existing_repo
git remote rename origin old-origin
git remote add origin http://`{old-domain}`/private/mybanks.git
git push -u origin --all
git push -u origin --tags

  1. 切换分支:git checkout -b <branch name>
  2. 设置远程URL:git branch --set-upstream-to=origin/<branch name>
  3. 修改远程URL:git remote set-url origin http://{new-domain}/cable/guide.git

  • 注:
  1. [2023-06-25] 原动态域名{old-domain}过期停用,改为{new-domain}
  2. [2023-09-04] 原服务器(CentOS8无法启动),启用{new-domain}.
  3. 更换远程url命令:git remote set-url origin 'http://`{new-domain}`/tips/linux.git'

Read More

Hello World

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

出现连接失败时的解决法

在PowerShell或者VSCode Terminal中执行命令前需要变更执行策略:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment