本文整理了Java中jodd.bean.BeanUtil.hasRootProperty()
方法的一些代码示例,展示了BeanUtil.hasRootProperty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BeanUtil.hasRootProperty()
方法的具体详情如下:
包路径:jodd.bean.BeanUtil
类名称:BeanUtil
方法名:hasRootProperty
[英]Returns true
if bean has only a root property. If yes, this means that property may be injected into the bean. If not, bean does not contain the property.
[中]如果bean只有根属性,则返回true
。如果是,这意味着可以将属性注入bean中。否则,bean不包含该属性。
代码示例来源:origin: oblac/jodd
/**
* Sets bean parameters from bean. Non-existing bean properties are ignored.
*/
public Q setBean(final String beanName, final Object bean) {
if (bean == null) {
return _this();
}
init();
final String beanNamePrefix = beanName + '.';
query.forEachNamedParameter(p -> {
final String paramName = p.name;
if (paramName.startsWith(beanNamePrefix)) {
final String propertyName = paramName.substring(beanNamePrefix.length());
if (BeanUtil.declared.hasRootProperty(bean, propertyName)) {
final Object value = BeanUtil.declared.getProperty(bean, propertyName);
setObject(paramName, value);
}
}
});
return _this();
}
代码示例来源:origin: oblac/jodd
@Test
void testMap3() {
Map m = new HashMap();
BeanUtil.pojo.setProperty(m, "Foo", "John");
assertEquals("John", m.get("Foo"));
assertNull(m.get("foo"));
assertFalse(BeanUtil.declared.hasProperty(m, "foo"));
assertFalse(BeanUtil.declared.hasRootProperty(m, "foo"));
BeanUtil.pojo.setProperty(m, "foo", new HashMap());
assertTrue(BeanUtil.declared.hasProperty(m, "foo"));
assertTrue(BeanUtil.declared.hasRootProperty(m, "foo"));
assertFalse(BeanUtil.declared.hasProperty(m, "foo.Name"));
assertTrue(BeanUtil.declared.hasRootProperty(m, "foo.Name"));
BeanUtil.pojo.setProperty(m, "foo.Name", "Doe");
assertEquals("John", m.get("Foo"));
assertEquals("Doe", ((HashMap) m.get("foo")).get("Name"));
assertNull(((HashMap) m.get("foo")).get("name"), "Doe not null");
assertEquals("John", BeanUtil.pojo.getProperty(m, "Foo"));
assertEquals("Doe", BeanUtil.pojo.getProperty(m, "foo.Name"));
try {
assertNull(BeanUtil.pojo.getProperty(m, "foo.name"));
fail("error");
} catch (Exception ignored) {
}
}
代码示例来源: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 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 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"));
}
代码示例来源:origin: oblac/jodd
assertTrue(BeanUtil.declared.hasProperty(x, "y"));
assertFalse(BeanUtil.declared.hasProperty(x, "y.foo"));
assertTrue(BeanUtil.declared.hasRootProperty(x, "y.foo"));
assertFalse(BeanUtil.declared.hasProperty(x, "y[23].foo"));
assertTrue(BeanUtil.declared.hasRootProperty(x, "y[23].foo"));
try {
BeanUtil.pojo.setProperty(x, "y.foo", "yyy");
assertTrue(BeanUtil.declared.hasRootProperty(x, "yy[2].foo"));
try {
BeanUtil.pojo.setProperty(x, "yy[2].foo", "yyy");
assertTrue(BeanUtil.declared.hasRootProperty(x, "yy[20].foo"));
BeanUtil.forced.setProperty(x, "yy[20].foo", "zzz");
assertTrue(BeanUtil.declared.hasProperty(x, "yy[20].foo"));
代码示例来源:origin: oblac/jodd
Dummy dummy = new Dummy();
assertTrue(BeanUtil.declared.hasProperty(fb4, "data[0].bbean.abean.fooProp"));
assertTrue(BeanUtil.declared.hasRootProperty(fb4, "data[0].bbean.abean.fooProp"));
assertEquals("xxx", BeanUtil.pojo.getProperty(fb4, "data[0].bbean.abean.fooProp"));
assertTrue(BeanUtil.declared.hasProperty(fb4, "data[1].bbean.abean.fooProp"));
assertTrue(BeanUtil.declared.hasRootProperty(fb4, "data[1].bbean.abean.fooProp"));
assertEquals("yyy", BeanUtil.pojo.getProperty(fb4, "data[1].bbean.abean.fooProp"));
assertTrue(BeanUtil.declared.hasRootProperty(fb4, "list[1].bbean.abean.fooProp"));
assertTrue(BeanUtil.declared.hasProperty(fb4, "list[1]"));
assertEquals("eee", BeanUtil.pojo.getProperty(fb4, "list[1]"));
代码示例来源:origin: org.jodd/jodd-db
/**
* Sets bean parameters from bean. Non-existing bean properties are ignored.
*/
public Q setBean(final String beanName, final Object bean) {
if (bean == null) {
return _this();
}
init();
final String beanNamePrefix = beanName + '.';
query.forEachNamedParameter(p -> {
final String paramName = p.name;
if (paramName.startsWith(beanNamePrefix)) {
final String propertyName = paramName.substring(beanNamePrefix.length());
if (BeanUtil.declared.hasRootProperty(bean, propertyName)) {
final Object value = BeanUtil.declared.getProperty(bean, propertyName);
setObject(paramName, value);
}
}
});
return _this();
}
内容来源于网络,如有侵权,请联系作者删除!