doc[storage]: Synchronize the latest documents.

This commit is contained in:
凌星 committed 2023-09-19 17:17:38 +08:00
1 parent 38375041dd
commit f045d44d37
9 files changed
+60 -15

No files matched your search

+22 -4
View File
@@ -19,6 +19,10 @@
![Image text](../doc/image/storage/storage02.png)
- 除此之外你还可以使用Java新特性提供的record类
![Image text](../doc/image/storage/storage03.png)
- 解析过后有两种使用方式
1. 通过注解
```
@@ -26,29 +30,43 @@
public class StudentManager {
@ResInjection
private Storage<Integer, StudentResource> studentResources;
private IStorage<Integer, StudentResource> studentStorage;
}
```
2. 通过类动态获取
```
Storage<Integer, StudentResource> studentResources = (Storage<Integer, StudentResource>) StorageContext.getStorageManager().getStorage(StudentResource.class);
IStorage<Integer, StudentResource> studentStorage = StorageContext.getStorageManager().getStorage(StudentResource.class);
```
- 通过id找到对应的行
```
var studentResource = studentResources.get(1000);
var studentResource = studentStorage.get(1000);
```
或者也可以通过如下方式获取
```
var resource = StorageContext.get(StudentResource.class, 1001);
```
- 通过索引找对应的行,默认为可重复的索引,返回了一个列表list
```
var students = studentResources.getIndex("name", "james0");
var students = studentStorage.getIndexes(StudentResource::getName, "james0");
```
如果你是record类则使用方式如下
```
var students = studentStorage.getIndexes(StudentResource::name, "james0");
```
- 唯一索引通过Storage.getUniqueIndex()获取,需要把索引注解标注为@Index(unique = true)
```
StudentResource student = storage.getUniqueIndex(StudentResource::idCard, "110101200007281903");
```
### Ⅲ. 热更新Excel/Json
- [tank](https://github.com/zfoo-project/tank-game-server/blob/main/common/src/main/java/com/zfoo/tank/common/util/HotUtils.java)