本文整理了Java中jodd.bean.BeanUtil.setProperty()
方法的一些代码示例,展示了BeanUtil.setProperty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BeanUtil.setProperty()
方法的具体详情如下:
包路径:jodd.bean.BeanUtil
类名称:BeanUtil
方法名:setProperty
[英]Sets Java Bean property.
[中]
代码示例来源:origin: redisson/redisson
/**
* Copies single property to the destination.
* Exceptions are ignored, so copying continues if
* destination does not have some of the sources properties.
*/
@Override
protected boolean visitProperty(String name, Object value) {
if (isTargetMap) {
name = LEFT_SQ_BRACKET + name + RIGHT_SQ_BRACKET;
}
beanUtil.setProperty(destination, name, value);
return true;
}
代码示例来源:origin: oblac/jodd
/**
* Copies single property to the destination.
* Exceptions are ignored, so copying continues if
* destination does not have some of the sources properties.
*/
@Override
protected boolean visitProperty(String name, final Object value) {
if (isTargetMap) {
name = LEFT_SQ_BRACKET + name + RIGHT_SQ_BRACKET;
}
beanUtil.setProperty(destination, name, value);
return true;
}
代码示例来源:origin: oblac/jodd
/**
* Reads filter config parameters and set into destination target.
*/
protected void readFilterConfigParameters(final FilterConfig filterConfig, final Object target, final String... parameters) {
for (String parameter : parameters) {
String value = filterConfig.getInitParameter(parameter);
if (value != null) {
BeanUtil.declared.setProperty(target, parameter, value);
}
}
}
代码示例来源:origin: oblac/jodd
/**
* Sets ID value for given entity.
*/
public void setIdValue(final E object, final Object value) {
final String propertyName = getIdPropertyName();
BeanUtil.declared.setProperty(object, propertyName, value);
}
代码示例来源:origin: oblac/jodd
@Test
void testSetPropertyForcedSilent() {
Bean bean = new Bean();
try {
BeanUtil.forcedSilent.setProperty(bean, "numbers[1].xxx", "173");
BeanUtil.forcedSilent.setProperty(bean, "map[aaa].xxx", "173");
BeanUtil.declaredForcedSilent.setProperty(bean, "someNumbers[3].foo", "173");
BeanUtil.declaredForcedSilent.setProperty(bean, "wee.foo", "173");
//BeanUtil.setDeclaredPropertyForcedSilent(bean, "someNumbers[mmm].foo", "173"); // no fast silent
//BeanUtil.setPropertyForcedSilent(bean, "strings[1]", "moo"); // no fast silent
}
catch (Exception ex) {
fail(ex.getMessage());
}
}
}
代码示例来源:origin: oblac/jodd
@Test
void testGeneralMapOnly() {
Map map = new HashMap();
BeanUtil.forced.setProperty(map, "foo.lll", "value");
assertNotNull(map.get("foo"));
assertEquals("value", ((Map) map.get("foo")).get("lll"));
map = new HashMap();
BeanUtil.forced.setProperty(map, "foo.lll[2]", "value");
assertNotNull(map.get("foo"));
assertNotNull(((Map) map.get("foo")).get("lll"));
assertEquals("value", ((Map) ((Map) map.get("foo")).get("lll")).get("2"));
}
代码示例来源:origin: oblac/jodd
/**
* Updates single property in database and in the bean.
*/
public <E> E updateProperty(final E entity, final String name, final Object newValue) {
query(dbOom.entities().updateColumn(entity, name, newValue)).autoClose().executeUpdate();
BeanUtil.declared.setProperty(entity, name, newValue);
return entity;
}
代码示例来源:origin: oblac/jodd
@Test
void testEnums() {
EnumBean enumBean = new EnumBean();
BeanUtil.pojo.setProperty(enumBean, "id", Integer.valueOf(123));
BeanUtil.pojo.setProperty(enumBean, "color", "RED");
BeanUtil.pojo.setProperty(enumBean, "status", "STARTED");
assertEquals(123, enumBean.getId());
assertEquals(Color.RED, enumBean.getColor());
assertEquals(Status.STARTED, enumBean.getStatus());
}
代码示例来源:origin: oblac/jodd
@Test
void testDeclared() {
FooBean3 fb = new FooBean3();
BeanUtil.declared.setProperty(fb, "pprotected", new Integer(1));
Integer value = BeanUtil.declared.getProperty(fb, "pprotected");
assertNotNull(value);
assertEquals(1, value.intValue());
BeanUtil.declared.setProperty(fb, "ppackage", new Integer(2));
value = BeanUtil.declared.getProperty(fb, "ppackage");
assertNotNull(value);
assertEquals(2, value.intValue());
BeanUtil.declared.setProperty(fb, "pprivate", new Integer(3));
value = BeanUtil.declared.getProperty(fb, "pprivate");
assertNotNull(value);
assertEquals(3, value.intValue());
}
代码示例来源:origin: oblac/jodd
@Test
void testGetSetMapWithIntegerKey() {
for (int i = 0; i < 2; i++) {
String suffix = "";
if (i == 1) {
suffix = "X";
}
Bean1 bean1 = new Bean1();
assertNull(BeanUtil.pojo.getProperty(bean1, "map2" + suffix));
try {
BeanUtil.pojo.setProperty(bean1, "map2" + suffix + "[0].data" + suffix, Integer.valueOf(173));
fail("error");
} catch (BeanException ignored) {
}
BeanUtil.forced.setProperty(bean1, "map2" + suffix + "[0].data" + suffix, Integer.valueOf(173));
assertNotNull(bean1.map2);
assertEquals(Integer.valueOf(173), bean1.map2.get(Integer.valueOf(0)).data);
}
}
代码示例来源:origin: oblac/jodd
@Test
void testGetSetMap() {
for (int i = 0; i < 2; i++) {
String suffix = "";
if (i == 1) {
suffix = "X";
}
Bean1 bean1 = new Bean1();
assertNull(BeanUtil.pojo.getProperty(bean1, "map1" + suffix));
try {
BeanUtil.pojo.setProperty(bean1, "map1" + suffix + "[x0].data" + suffix, Integer.valueOf(173));
fail("error");
} catch (BeanException ignored) {
}
BeanUtil.forced.setProperty(bean1, "map1" + suffix + "[x0].data" + suffix, Integer.valueOf(173));
assertNotNull(bean1.map1);
assertEquals(Integer.valueOf(173), bean1.map1.get("x0").data);
}
}
代码示例来源:origin: oblac/jodd
@Test
void testCollections() {
MixBean mixBean = new MixBean();
BeanUtil.pojo.setProperty(mixBean, "data", "1,2,3");
assertNotNull(mixBean.data);
assertEquals(3, mixBean.data.size());
assertEquals(1, mixBean.data.get(0).intValue());
BeanUtil.pojo.setProperty(mixBean, "data2", "1,2,3,4");
assertNotNull(mixBean.getData2());
assertEquals(4, mixBean.getData2().size());
assertEquals(1, mixBean.getData2().get(0).intValue());
BeanUtil.pojo.setProperty(mixBean, "data5", "1,2,3,4,5");
assertNotNull(mixBean.getData5());
assertEquals(5, mixBean.getData5().size());
assertEquals(1, mixBean.getData5().get(0).intValue());
}
代码示例来源:origin: oblac/jodd
@Test
void testSetPropertyMath() {
FooBean2 fb = new FooBean2();
String propName = "fooBigDecimal";
assertEquals(BigDecimal.class, BeanUtil.pojo.getPropertyType(fb, propName));
BeanUtil.pojo.setProperty(fb, propName, new BigDecimal("1.2"));
assertEquals(1.2, fb.getFooBigDecimal().doubleValue(), 0.0005);
}
代码示例来源:origin: oblac/jodd
@Test
void testMap() {
Cbean cbean = new Cbean();
Abean abean = cbean.getBbean().getAbean();
assertNull(BeanUtil.declared.getPropertyType(abean, "mval"));
BeanUtil.pojo.setProperty(abean, "mval", new Integer(173));
BeanUtil.pojo.setProperty(abean, "mval2", new Integer(1));
assertEquals((abean.get("mval")).intValue(), 173);
assertEquals(173, ((Integer) BeanUtil.pojo.getProperty(abean, "mval")).intValue());
assertEquals(1, ((Integer) BeanUtil.pojo.getProperty(abean, "mval2")).intValue());
assertTrue(BeanUtil.declared.hasProperty(cbean, "bbean.abean.mval"));
assertTrue(BeanUtil.declared.hasRootProperty(cbean, "bbean.abean.mval"));
BeanUtil.pojo.setProperty(cbean, "bbean.abean.mval", new Integer(3));
assertEquals(3, ((Integer) BeanUtil.pojo.getProperty(abean, "mval")).intValue());
assertEquals(3, ((Integer) BeanUtil.pojo.getProperty(cbean, "bbean.abean.mval")).intValue());
HashMap map = new HashMap();
BeanUtil.pojo.setProperty(map, "val1", new Integer(173));
assertEquals(173, ((Integer) map.get("val1")).intValue());
Integer i = BeanUtil.pojo.getProperty(map, "val1");
assertEquals(173, i.intValue());
}
代码示例来源:origin: oblac/jodd
@Test
void testSubSup2() {
SupBean supBean = new SubBean();
BeanUtil.pojo.setProperty(supBean, "v2", "V2");
//String v = (String) BeanUtil.pojo.getProperty(supBean, "v2");
String v = BeanUtil.pojo.getProperty(supBean, "v2");
assertEquals("V2sub", v);
}
代码示例来源:origin: oblac/jodd
@Test
void testSilent() {
FooBean fb = new FooBean();
assertFalse(BeanUtil.declared.hasProperty(fb, "notexisting"));
assertFalse(BeanUtil.declared.hasRootProperty(fb, "notexisting"));
try {
BeanUtil.pojo.setProperty(fb, "notexisting", null);
fail("error");
} catch (Exception ignored) {
}
try {
BeanUtil.silent.setProperty(fb, "notexisting", null);
} catch (Exception ex) {
fail("error");
}
}
代码示例来源:origin: oblac/jodd
@Test
void testSubSup1() {
SupBean supBean = new SupBean();
//BeanUtil.pojo.setProperty(supBean, "v1", "V1");
String v = BeanUtil.pojo.getProperty(supBean, "v1");
assertEquals("v1sup", v);
supBean = new SubBean();
BeanUtil.pojo.setProperty(supBean, "v1", "V1");
v = BeanUtil.pojo.getProperty(supBean, "v1");
assertEquals("V1sup", v);
}
代码示例来源:origin: oblac/jodd
@Test
void testInjection() {
WebApp webapp = new WebApp();
webapp.start();
PetiteContainer madpc = webapp.madvocContainer().getPetiteContainer();
String baseName = StringUtil.uncapitalize(FooBean.class.getSimpleName());
madpc.defineParameter("foo", "1");
madpc.defineParameter(baseName + ".integer", "173");
madpc.defineParameter(baseName + ".string", "jodd");
madpc.defineParameter(baseName, "huh");
ParamsScope paramsScope = new ParamsScope();
BeanUtil.declared.setProperty(paramsScope, "madpc", madpc);
FooBean fooBean = new FooBean();
paramsScope.inject(new Targets(fooBean, null));
assertEquals(173, fooBean.getInteger().intValue());
assertEquals("jodd", fooBean.getString());
}
}
代码示例来源:origin: oblac/jodd
@Test
void testToBean() {
String data = "port=10101\n" +
"address=localhost\n" +
"pool=30\n" +
"foo=bar";
final Props props = new Props();
props.load(data);
final HttpConfig httpConfig = new HttpConfig();
props.entries().forEach(pe -> BeanUtil.silent.setProperty(httpConfig, pe.getKey(), pe.getValue()));
assertEquals(10101, httpConfig.port);
assertEquals(30, httpConfig.pool);
assertEquals("localhost", httpConfig.address);
}
}
代码示例来源:origin: oblac/jodd
@Test
void testNested() {
Cbean cbean = new Cbean();
String value = "testnest";
String value2 = "nesttest";
assertEquals(String.class, BeanUtil.declared.getPropertyType(cbean, "bbean.abean.fooProp"));
assertTrue(BeanUtil.declared.hasProperty(cbean, "bbean.abean.fooProp"));
assertTrue(BeanUtil.declared.hasRootProperty(cbean, "bbean.abean.fooProp"));
BeanUtil.pojo.setProperty(cbean, "bbean.abean.fooProp", value);
assertEquals(value, BeanUtil.pojo.getProperty(cbean, "bbean.abean.fooProp"));
Bbean bbean = BeanUtil.pojo.getProperty(cbean, "bbean");
assertTrue(BeanUtil.declared.hasProperty(bbean, "abean.fooProp"));
assertTrue(BeanUtil.declared.hasRootProperty(bbean, "abean.fooProp"));
assertEquals(value, BeanUtil.pojo.getProperty(bbean, "abean.fooProp"));
Abean abean = BeanUtil.pojo.getProperty(bbean, "abean");
assertEquals(value, BeanUtil.pojo.getProperty(abean, "fooProp"));
BeanUtil.pojo.setProperty(bbean, "abean.fooProp", value2);
assertEquals(value2, BeanUtil.pojo.getProperty(bbean, "abean.fooProp"));
}
内容来源于网络,如有侵权,请联系作者删除!