mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
Revert "增强ActiveEntity,使其可以使用getter对应的lambda取值或设置条件"
This reverts commit cbebecda58
.
This commit is contained in:
@@ -1,35 +0,0 @@
|
|||||||
package cn.hutool.db;
|
|
||||||
|
|
||||||
import cn.hutool.core.lang.func.Func1;
|
|
||||||
import cn.hutool.core.lang.func.LambdaUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 支持lambda的Entity
|
|
||||||
*
|
|
||||||
* @author VampireAchao
|
|
||||||
*/
|
|
||||||
public class LambdaEntity<T> extends ActiveEntity {
|
|
||||||
|
|
||||||
public LambdaEntity(T entity) {
|
|
||||||
super(parse(entity));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <R> R get(Func1<T, R> field) {
|
|
||||||
return (R) super.get(LambdaUtil.getFieldName(field));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public LambdaEntity<T> set(Func1<T, ?> field, Object value) {
|
|
||||||
return (LambdaEntity<T>) super.set(LambdaUtil.getFieldName(field), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public LambdaEntity<T> setIgnoreNull(Func1<T, ?> field, Object value) {
|
|
||||||
if (null != field && null != value) {
|
|
||||||
return (LambdaEntity<T>) set(LambdaUtil.getFieldName(field), value);
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -120,14 +120,6 @@ public class CRUDTest {
|
|||||||
Assert.assertFalse(entity.isEmpty());
|
Assert.assertFalse(entity.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void lambdaSetTest() {
|
|
||||||
LambdaEntity<User> entity = new LambdaEntity<>(new User());
|
|
||||||
entity.set(User::getAge, 66).load();
|
|
||||||
Assert.assertEquals(new Integer(66), entity.get(User::getAge));
|
|
||||||
Assert.assertFalse(entity.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对增删改查做单元测试
|
* 对增删改查做单元测试
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user