Merge pull request !67 from 王帅/main
This commit is contained in:
Michael Yang 2023-06-14 12:08:40 +00:00 committed by Gitee
commit ee0e3f7465
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 63 additions and 7 deletions

View File

@ -25,6 +25,7 @@ import com.mybatisflex.core.util.CollectionUtil;
import com.mybatisflex.core.util.StringUtil;
import org.apache.ibatis.io.ResolverUtil;
import org.apache.ibatis.reflection.Reflector;
import org.apache.ibatis.reflection.TypeParameterResolver;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;
@ -216,7 +217,7 @@ public class TableInfoFactory {
) {
// 集合嵌套
if (Collection.class.isAssignableFrom(fieldType)) {
Type genericType = field.getGenericType();
Type genericType = TypeParameterResolver.resolveFieldType(field, entityClass);
if (genericType instanceof ParameterizedType){
Class<?> actualTypeArgument = (Class<?>) ((ParameterizedType) genericType).getActualTypeArguments()[0];
//需排除 List<String> List<Long> 等场景

View File

@ -19,8 +19,8 @@ import com.mybatisflex.annotation.Table;
import java.util.Date;
@Table(value = "tb_account",onSet = AccountOnSetListener.class)
public class Account extends BaseEntity<String, Long> {
@Table(value = "tb_account", onSet = AccountOnSetListener.class)
public class Account extends BaseEntity<String, Long, String> {
/*@Id(keyType = KeyType.Auto)
private Long id;*/
@ -77,6 +77,7 @@ public class Account extends BaseEntity<String, Long> {
", userName='" + userName + '\'' +
", age=" + age +
", birthday=" + birthday +
", list=" + roles +
'}';
}
}

View File

@ -16,13 +16,25 @@
package com.mybatisflex.test.model;
import java.util.List;
/**
* @author 王帅
* @since 2.0
*/
public class BaseEntity<T, ID> extends IdEntity<ID> {
public class BaseEntity<T, ID, L> extends IdEntity<ID> {
protected T userName;
protected List<L> roles;
public List<L> getRoles() {
return roles;
}
public void setRoles(List<L> roles) {
this.roles = roles;
}
public T getUserName() {
return userName;

View File

@ -16,14 +16,16 @@
package com.mybatisflex.test.model;
import com.mybatisflex.annotation.EnumValue;
/**
* @author 王帅
* @since 2023-06-14
*/
public enum Gender {
MALE, FEMALE;
/*MALE(1), FEMALE(0);
// MALE, FEMALE;
MALE(1), FEMALE(0);
public int getCode() {
return code;
@ -34,6 +36,6 @@ public enum Gender {
Gender(int code) {
this.code = code;
}*/
}
}

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.ClassUtil;
import com.mybatisflex.test.model.Account;
import org.apache.ibatis.reflection.TypeParameterResolver;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
/**
* @author 王帅
* @since 2023-06-14
*/
class ReflectTest {
@Test
void test() {
Field field = ClassUtil.getAllFields(Account.class, f -> f.getName().equals("list")).get(0);
Type type = TypeParameterResolver.resolveFieldType(field, Account.class);
System.out.println(type);
}
}