mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
Merge pull request !67 from 王帅/main
This commit is contained in:
commit
ee0e3f7465
@ -25,6 +25,7 @@ import com.mybatisflex.core.util.CollectionUtil;
|
|||||||
import com.mybatisflex.core.util.StringUtil;
|
import com.mybatisflex.core.util.StringUtil;
|
||||||
import org.apache.ibatis.io.ResolverUtil;
|
import org.apache.ibatis.io.ResolverUtil;
|
||||||
import org.apache.ibatis.reflection.Reflector;
|
import org.apache.ibatis.reflection.Reflector;
|
||||||
|
import org.apache.ibatis.reflection.TypeParameterResolver;
|
||||||
import org.apache.ibatis.session.Configuration;
|
import org.apache.ibatis.session.Configuration;
|
||||||
import org.apache.ibatis.type.JdbcType;
|
import org.apache.ibatis.type.JdbcType;
|
||||||
import org.apache.ibatis.type.TypeHandler;
|
import org.apache.ibatis.type.TypeHandler;
|
||||||
@ -216,7 +217,7 @@ public class TableInfoFactory {
|
|||||||
) {
|
) {
|
||||||
// 集合嵌套
|
// 集合嵌套
|
||||||
if (Collection.class.isAssignableFrom(fieldType)) {
|
if (Collection.class.isAssignableFrom(fieldType)) {
|
||||||
Type genericType = field.getGenericType();
|
Type genericType = TypeParameterResolver.resolveFieldType(field, entityClass);
|
||||||
if (genericType instanceof ParameterizedType){
|
if (genericType instanceof ParameterizedType){
|
||||||
Class<?> actualTypeArgument = (Class<?>) ((ParameterizedType) genericType).getActualTypeArguments()[0];
|
Class<?> actualTypeArgument = (Class<?>) ((ParameterizedType) genericType).getActualTypeArguments()[0];
|
||||||
//需排除 List<String> List<Long> 等场景
|
//需排除 List<String> List<Long> 等场景
|
||||||
|
|||||||
@ -19,8 +19,8 @@ import com.mybatisflex.annotation.Table;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@Table(value = "tb_account",onSet = AccountOnSetListener.class)
|
@Table(value = "tb_account", onSet = AccountOnSetListener.class)
|
||||||
public class Account extends BaseEntity<String, Long> {
|
public class Account extends BaseEntity<String, Long, String> {
|
||||||
|
|
||||||
/*@Id(keyType = KeyType.Auto)
|
/*@Id(keyType = KeyType.Auto)
|
||||||
private Long id;*/
|
private Long id;*/
|
||||||
@ -77,6 +77,7 @@ public class Account extends BaseEntity<String, Long> {
|
|||||||
", userName='" + userName + '\'' +
|
", userName='" + userName + '\'' +
|
||||||
", age=" + age +
|
", age=" + age +
|
||||||
", birthday=" + birthday +
|
", birthday=" + birthday +
|
||||||
|
", list=" + roles +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,13 +16,25 @@
|
|||||||
|
|
||||||
package com.mybatisflex.test.model;
|
package com.mybatisflex.test.model;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 王帅
|
* @author 王帅
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public class BaseEntity<T, ID> extends IdEntity<ID> {
|
public class BaseEntity<T, ID, L> extends IdEntity<ID> {
|
||||||
|
|
||||||
protected T userName;
|
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() {
|
public T getUserName() {
|
||||||
return userName;
|
return userName;
|
||||||
|
|||||||
@ -16,14 +16,16 @@
|
|||||||
|
|
||||||
package com.mybatisflex.test.model;
|
package com.mybatisflex.test.model;
|
||||||
|
|
||||||
|
import com.mybatisflex.annotation.EnumValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 王帅
|
* @author 王帅
|
||||||
* @since 2023-06-14
|
* @since 2023-06-14
|
||||||
*/
|
*/
|
||||||
public enum Gender {
|
public enum Gender {
|
||||||
|
|
||||||
MALE, FEMALE;
|
// MALE, FEMALE;
|
||||||
/*MALE(1), FEMALE(0);
|
MALE(1), FEMALE(0);
|
||||||
|
|
||||||
public int getCode() {
|
public int getCode() {
|
||||||
return code;
|
return code;
|
||||||
@ -34,6 +36,6 @@ public enum Gender {
|
|||||||
|
|
||||||
Gender(int code) {
|
Gender(int code) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user