test[storage]: record class test

This commit is contained in:
godotg
2023-09-19 20:56:09 +08:00
parent 7ba3cc8d6a
commit 2cc4adfef9
5 changed files with 43 additions and 40 deletions
@@ -23,7 +23,6 @@ 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;
@@ -38,13 +37,6 @@ 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() {
@@ -1,30 +0,0 @@
package com.zfoo.storage;
import com.zfoo.storage.anno.AliasFieldName;
import com.zfoo.storage.anno.Id;
import com.zfoo.storage.anno.Index;
import com.zfoo.storage.anno.Storage;
import com.zfoo.storage.resource.User;
import java.util.List;
/**
* @author veione
*/
@Storage
public record StudentResource(
@Id
int id,
@Index(unique = true)
String idCard,
@Index
String name,
@AliasFieldName("年龄")
int age,
float score,
String[] courses,
User[] users,
List<User> userList,
User user
) {
}
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2020 The zfoo Authors
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.storage.resource;
import com.zfoo.storage.anno.AliasFieldName;
import com.zfoo.storage.anno.Id;
import com.zfoo.storage.anno.Index;
import com.zfoo.storage.anno.Storage;
import java.util.List;
/**
* @author veione
*/
@Storage
public record TeacherResource(
@Id
int id,
@Index(unique = true)
String idCard,
@Index
String name,
@AliasFieldName("年龄")
int age,
float score,
String[] courses,
User[] users,
List<User> userList,
User user
) {
}
@@ -1,6 +1,6 @@
package com.zfoo.storage.util.lambda;
import com.zfoo.storage.StudentResource;
import com.zfoo.storage.resource.TeacherResource;
import com.zfoo.storage.util.LambdaUtils;
import com.zfoo.storage.util.function.Func1;
import org.junit.Test;
@@ -15,7 +15,7 @@ public class TestLambdaFunction {
//https://blog.csdn.net/iteye_19045/article/details/119299015
@Test
public void testFuncSerialization() throws Exception {
Func1<StudentResource, String> func = StudentResource::name;
Func1<TeacherResource, String> func = TeacherResource::name;
Object object = getObject(func);
System.out.println(object);