mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
fixed gitee issues; close #I6WGSA
This commit is contained in:
parent
04b98b9e69
commit
24aa327cdd
@ -46,7 +46,7 @@ public class FlexEnumTypeHandler<E extends Enum<E>> extends BaseTypeHandler<E> {
|
||||
return methodName.equals(fieldGetterName);
|
||||
});
|
||||
|
||||
enumPropertyType = field.getType();
|
||||
enumPropertyType = ClassUtil.wrap(field.getType());
|
||||
enums = enumClass.getEnumConstants();
|
||||
|
||||
if (allMethods.isEmpty()){
|
||||
@ -115,4 +115,5 @@ public class FlexEnumTypeHandler<E extends Enum<E>> extends BaseTypeHandler<E> {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -67,6 +67,34 @@ public class ClassUtil {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
|
||||
public static Class<?> wrap(Class<?> clazz) {
|
||||
if (clazz == null || !clazz.isPrimitive()) {
|
||||
return clazz;
|
||||
}
|
||||
if (clazz == Integer.TYPE) {
|
||||
return Integer.class;
|
||||
} else if (clazz == Long.TYPE) {
|
||||
return Long.class;
|
||||
} else if (clazz == Boolean.TYPE) {
|
||||
return Boolean.class;
|
||||
} else if (clazz == Float.TYPE) {
|
||||
return Float.class;
|
||||
} else if (clazz == Double.TYPE) {
|
||||
return Double.class;
|
||||
} else if (clazz == Short.TYPE) {
|
||||
return Short.class;
|
||||
} else if (clazz == Character.TYPE) {
|
||||
return Character.class;
|
||||
} else if (clazz == Byte.TYPE) {
|
||||
return Byte.class;
|
||||
} else if (clazz == Void.TYPE) {
|
||||
return Void.class;
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
||||
|
||||
public static <T> T newInstance(Class<T> clazz) {
|
||||
try {
|
||||
Constructor<?> defaultConstructor = null;
|
||||
|
||||
@ -22,6 +22,8 @@ public class Account extends BaseAccount implements Serializable {
|
||||
|
||||
private int age;
|
||||
|
||||
private SexEnum sex;
|
||||
|
||||
private Date birthday;
|
||||
|
||||
@Column("DEPT_ID_")
|
||||
@ -61,6 +63,14 @@ public class Account extends BaseAccount implements Serializable {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public SexEnum getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
public void setSex(SexEnum sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public Date getBirthday() {
|
||||
return birthday;
|
||||
}
|
||||
@ -108,14 +118,18 @@ public class Account extends BaseAccount implements Serializable {
|
||||
// this.deleteFlag = deleteFlag;
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Account{" +
|
||||
"id=" + id +
|
||||
", userName='" + userName + '\'' +
|
||||
", age=" + age +
|
||||
", sex=" + sex +
|
||||
", birthday=" + birthday +
|
||||
", deptId='" + deptId + '\'' +
|
||||
", options=" + options +
|
||||
", typeEnum=" + typeEnum +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,10 +23,6 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mybatisflex.core.query.QueryMethods.select;
|
||||
import static com.mybatisflex.test.table.Tables.ACCOUNT;
|
||||
|
||||
public class EntityTestStarter {
|
||||
|
||||
@ -55,7 +51,13 @@ public class EntityTestStarter {
|
||||
// System.out.println(account);
|
||||
|
||||
AccountMapper accountMapper = bootstrap.getMapper(AccountMapper.class);
|
||||
// Account account = accountMapper.selectOneById(1);
|
||||
Account account = accountMapper.selectOneById(1);
|
||||
System.out.println(account);
|
||||
|
||||
account.setSex(SexEnum.TYPE3);
|
||||
accountMapper.update(account);
|
||||
account = accountMapper.selectOneById(1);
|
||||
System.out.println(account);
|
||||
|
||||
|
||||
// QueryWrapper query = QueryWrapper.create().where(SYS_CONFIG.TYPE.eq(type).when(StrChecker.isNotBlank(type)))
|
||||
@ -74,12 +76,16 @@ public class EntityTestStarter {
|
||||
// )
|
||||
// );
|
||||
|
||||
List<Account> accounts = accountMapper.selectListByQuery(
|
||||
select().where(ACCOUNT.AGE.ge(18))
|
||||
.and(ACCOUNT.USER_NAME.like(null))
|
||||
.and(ACCOUNT.ID.ge(null))
|
||||
);
|
||||
System.out.println(accounts);
|
||||
|
||||
// Page<Account> paginate = accountMapper.paginate(1, 10, QueryWrapper.create());
|
||||
// System.out.println(paginate);
|
||||
//
|
||||
// List<Account> accounts = accountMapper.selectListByQuery(
|
||||
// select().where(ACCOUNT.AGE.ge(18))
|
||||
// .and(ACCOUNT.USER_NAME.like(null))
|
||||
// .and(ACCOUNT.ID.ge(null))
|
||||
// );
|
||||
// System.out.println(accounts);
|
||||
//
|
||||
// long l = accountMapper.selectCountByQuery(QueryWrapper.create());
|
||||
// System.out.println("count: "+ l);
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
package com.mybatisflex.test;
|
||||
|
||||
import com.mybatisflex.annotation.EnumValue;
|
||||
|
||||
public enum SexEnum {
|
||||
TYPE1(0,"女"),
|
||||
TYPE2(1,"男"),
|
||||
TYPE3(2,"未知"),
|
||||
|
||||
;
|
||||
|
||||
@EnumValue
|
||||
private int code;
|
||||
|
||||
private String desc;
|
||||
|
||||
SexEnum(int code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,3 @@
|
||||
INSERT INTO tb_account
|
||||
VALUES (1, '张三', 18, '2020-01-11', null),
|
||||
(2, '王麻子叔叔', 19, '2021-03-21', null);
|
||||
VALUES (1, '张三', 18, 0,'2020-01-11', null),
|
||||
(2, '王麻子叔叔', 19, 1, '2021-03-21', null);
|
||||
@ -3,6 +3,7 @@ CREATE TABLE IF NOT EXISTS `tb_account`
|
||||
`id` INTEGER PRIMARY KEY auto_increment,
|
||||
`user_name` VARCHAR(100),
|
||||
`age` Integer,
|
||||
`sex` Integer,
|
||||
`birthday` DATETIME,
|
||||
`options` VARCHAR(1024)
|
||||
);
|
||||
Loading…
x
Reference in New Issue
Block a user