mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-14 08:58:59 +00:00
doc[storage]: Synchronize the latest documents.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 88 KiB After Width: | Height: | Size: 53 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 48 KiB |
+24
-4
@@ -21,6 +21,10 @@ English | [简体中文](./README_CN.md)
|
||||
|
||||

|
||||
|
||||
- In addition, you can also use the record class provided by Java's new features
|
||||
|
||||

|
||||
|
||||
- After parsing, there are two ways to use it
|
||||
1. By annotation
|
||||
```
|
||||
@@ -28,13 +32,13 @@ English | [简体中文](./README_CN.md)
|
||||
public class StudentManager {
|
||||
|
||||
@ResInjection
|
||||
private Storage<Integer, StudentResource> studentResources;
|
||||
private IStorage<Integer, StudentResource> studentResources;
|
||||
|
||||
}
|
||||
```
|
||||
2. Dynamically obtained through classes
|
||||
```
|
||||
Storage<Integer, StudentResource> studentResources = (Storage<Integer, StudentResource>) StorageContext.getStorageManager().getStorage(StudentResource.class);
|
||||
IStorage<Integer, StudentResource> studentResources = StorageContext.getStorageManager().getStorage(StudentResource.class);
|
||||
```
|
||||
|
||||
- Find the corresponding row by id
|
||||
@@ -43,19 +47,35 @@ English | [简体中文](./README_CN.md)
|
||||
var studentResource = studentResources.get(1000);
|
||||
```
|
||||
|
||||
Alternatively, it can be obtained through the following methods
|
||||
|
||||
```
|
||||
var resource = StorageContext.get(StudentResource.class, 1001);
|
||||
```
|
||||
|
||||
- Find the corresponding row by index, default to a repeatable index, and return a list
|
||||
|
||||
```
|
||||
var students = studentResources.getIndex("name", "james0");
|
||||
var students = studentResources.getIndex(StudentResource::getName, "james0");
|
||||
```
|
||||
|
||||
If you are a record class, the usage is as follows
|
||||
|
||||
```
|
||||
var students = studentStorage.getIndexes(StudentResource::name, "james0");
|
||||
```
|
||||
|
||||
- The unique index is obtained through Storage.getUniqueIndex(), and the index annotation needs to be marked as @Index(
|
||||
unique = true)
|
||||
|
||||
```
|
||||
StudentResource student = storage.getUniqueIndex(StudentResource::idCard, "110101200007281903");
|
||||
```
|
||||
|
||||
### Ⅲ. Hot update Excel Json
|
||||
|
||||
- [tank](https://github.com/zfoo-project/tank-game-server/blob/main/common/src/main/java/com/zfoo/tank/common/util/HotUtils.java)
|
||||
Distributed hot update Excel Jsoncsv configuration file implementation
|
||||
Distributed hot update Excel Json csv configuration file implementation
|
||||
|
||||
### Ⅳ. Use
|
||||
|
||||
|
||||
+22
-4
@@ -19,6 +19,10 @@
|
||||
|
||||

|
||||
|
||||
- 除此之外你还可以使用Java新特性提供的record类
|
||||
|
||||

|
||||
|
||||
- 解析过后有两种使用方式
|
||||
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)
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.zfoo.storage.resource.StudentResource;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import java.util.List;
|
||||
@@ -36,6 +37,14 @@ public class ApplicationTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ApplicationTest.class);
|
||||
|
||||
|
||||
@Autowired
|
||||
public String testSpringInject(IStorage<Integer, StudentResource> studentStorage) {
|
||||
StudentResource resource = studentStorage.get(1001);
|
||||
|
||||
return resource.getName();
|
||||
}
|
||||
|
||||
// storage教程
|
||||
@Test
|
||||
public void startStorageTest() {
|
||||
@@ -47,6 +56,7 @@ public class ApplicationTest {
|
||||
// Excel的映射内容需要在被Spring管理的bean的方法上加上@ResInjection注解,即可自动注入Excel对应的对象
|
||||
// 参考StudentManager中的标准用法
|
||||
|
||||
IStorage<Integer, StudentResource> storage1 = StorageContext.getStorageManager().getStorage(StudentResource.class);
|
||||
|
||||
//获取所有数据
|
||||
List<StudentResource> list = StorageContext.getList(StudentResource.class);
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* @author veione
|
||||
* @version 1.0.0
|
||||
*/
|
||||
@Storage
|
||||
public record StudentResource(
|
||||
|
||||
+1
-2
@@ -1,4 +1,4 @@
|
||||
package com.zfoo.storage;
|
||||
package com.zfoo.storage.util.support;
|
||||
|
||||
import com.zfoo.protocol.util.FieldUtils;
|
||||
import org.junit.Test;
|
||||
@@ -7,7 +7,6 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author veione
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class TestFieldUtils {
|
||||
|
||||
+2
-2
@@ -1,5 +1,6 @@
|
||||
package com.zfoo.storage;
|
||||
package com.zfoo.storage.util.support;
|
||||
|
||||
import com.zfoo.storage.StudentResource;
|
||||
import com.zfoo.storage.util.LambdaUtils;
|
||||
import com.zfoo.storage.util.function.Func1;
|
||||
import com.zfoo.storage.util.support.LambdaMeta;
|
||||
@@ -11,7 +12,6 @@ import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @author veione
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class TestLambdaFunction {
|
||||
//https://blog.csdn.net/iteye_19045/article/details/119299015
|
||||
+1
-2
@@ -1,4 +1,4 @@
|
||||
package com.zfoo.storage;
|
||||
package com.zfoo.storage.util.support;
|
||||
|
||||
import com.zfoo.storage.resource.StudentResource;
|
||||
import com.zfoo.storage.util.LambdaUtils;
|
||||
@@ -7,7 +7,6 @@ import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author veione
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class TestLambdaFunctionCache {
|
||||
|
||||
Reference in New Issue
Block a user