From 67dd7d1bcfbdf438a1375ce83f5d4472b9d3be27 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Tue, 13 Jun 2023 14:56:33 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=B5=8B=E8=AF=95=E5=AE=9E=E4=BD=93?= =?UTF-8?q?=E7=B1=BB=E6=B3=9B=E5=9E=8B=E7=9A=84=E6=94=AF=E6=8C=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mybatisflex/test/model/Account.java | 10 ++- .../mybatisflex/test/model/BaseEntity.java | 34 +++++++++ .../com/mybatisflex/test/model/IdEntity.java | 40 +++++++++++ .../mybatisflex/test/common/FieldTest.java | 71 +++++++++++++++++++ .../test/mapper/AccountMapperTest.java | 65 +++++++++++++++++ 5 files changed, 214 insertions(+), 6 deletions(-) create mode 100644 mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/BaseEntity.java create mode 100644 mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/IdEntity.java create mode 100644 mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/FieldTest.java create mode 100644 mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/AccountMapperTest.java diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Account.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Account.java index 3d7fa200..6f0d21f9 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Account.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/Account.java @@ -15,18 +15,16 @@ */ package com.mybatisflex.test.model; -import com.mybatisflex.annotation.Id; -import com.mybatisflex.annotation.KeyType; import com.mybatisflex.annotation.Table; import java.util.Date; @Table(value = "tb_account",onSet = AccountOnSetListener.class) -public class Account { +public class Account extends BaseEntity { - @Id(keyType = KeyType.Auto) - private Long id; - private String userName; + /*@Id(keyType = KeyType.Auto) + private Long id;*/ + //private String userName; private Integer age; private Date birthday; diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/BaseEntity.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/BaseEntity.java new file mode 100644 index 00000000..09b7a559 --- /dev/null +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/BaseEntity.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * 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.mybatisflex.test.model; + +/** + * @author 王帅 + * @since 2.0 + */ +public class BaseEntity extends IdEntity { + + protected T userName; + + public T getUserName() { + return userName; + } + + public void setUserName(T userName) { + this.userName = userName; + } +} \ No newline at end of file diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/IdEntity.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/IdEntity.java new file mode 100644 index 00000000..2baa5af4 --- /dev/null +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/model/IdEntity.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * 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.mybatisflex.test.model; + +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.KeyType; + +import java.io.Serializable; + +/** + * @author 王帅 + * @since 2023-06-13 + */ +public class IdEntity implements Serializable { + + @Id(keyType = KeyType.Auto) + protected T id; + + public T getId() { + return id; + } + + public void setId(T id) { + this.id = id; + } +} \ No newline at end of file diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/FieldTest.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/FieldTest.java new file mode 100644 index 00000000..5f7587e0 --- /dev/null +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/FieldTest.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * 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.mybatisflex.test.common; + +import com.mybatisflex.core.util.StringUtil; +import com.mybatisflex.test.model.Account; +import com.mybatisflex.test.model.BaseEntity; +import com.mybatisflex.test.model.UserVO; +import org.apache.ibatis.reflection.Reflector; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.List; + +/** + * @author 王帅 + * @since 2023-06-13 + */ +class FieldTest { + + @Test + void test() { + String genericString = BaseEntity.class.toGenericString(); + System.out.println(genericString); + List genericParameters = StringUtil.getGenericParameters(genericString); + System.out.println(genericParameters); + } + + @Test + void test02() { + Class accountClass = Account.class; + Method[] declaredMethods = accountClass.getMethods(); + Arrays.stream(declaredMethods) + .filter(e -> e.getName().startsWith("get")) + .forEach(System.out::println); + } + + @Test + void test03() { + Reflector reflector = new Reflector(Account.class); + Class id = reflector.getGetterType("id"); + Class userName = reflector.getGetterType("userName"); + Class age = reflector.getGetterType("age"); + System.out.println(id); + System.out.println(userName); + System.out.println(age); + } + + @Test + void test04() { + Reflector reflector = new Reflector(UserVO.class); + Class roleList = reflector.getGetterType("roleList"); + System.out.println(roleList); + } + +} \ No newline at end of file diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/AccountMapperTest.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/AccountMapperTest.java new file mode 100644 index 00000000..84ed06ed --- /dev/null +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/AccountMapperTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * 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.mybatisflex.test.mapper; + +import com.mybatisflex.core.query.QueryWrapper; +import com.mybatisflex.test.model.Account; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.Date; + +/** + * @author 王帅 + * @since 2023-06-13 + */ +@SpringBootTest +@SuppressWarnings("all") +class AccountMapperTest { + + @Autowired + private AccountMapper accountMapper; + + @Test + void testInsert() { + Account account = new Account(); + account.setBirthday(new Date()); + account.setUserName("张三"); + account.setAge(18); + accountMapper.insert(account); + } + + @Test + void testUpdate() { + Account account = new Account(); + account.setId(1L); + account.setAge(58); + accountMapper.update(account); + } + + @Test + void testDelete() { + accountMapper.deleteById(1L); + } + + @Test + void testSelect() { + accountMapper.selectListByQuery(QueryWrapper.create()).forEach(System.err::println); + } + +} \ No newline at end of file