jodd.bean.BeanUtil.getProperty()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(198)

本文整理了Java中jodd.bean.BeanUtil.getProperty()方法的一些代码示例,展示了BeanUtil.getProperty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BeanUtil.getProperty()方法的具体详情如下:
包路径:jodd.bean.BeanUtil
类名称:BeanUtil
方法名:getProperty

BeanUtil.getProperty介绍

[英]Returns value of bean's property.

In silent mode, returning of null is ambiguous: it may means that property name is valid and property value is null or that property name is invalid.

Using forced mode does not have any influence on the result.
[中]返回bean属性的值。
在静默模式下,返回null是不明确的:这可能意味着属性名有效,属性值为null,或者属性名无效。
使用强制模式对结果没有任何影响。

代码示例

代码示例来源:origin: redisson/redisson

public String resolve(String macroName) {
    Object value = BeanUtil.declaredSilent.getProperty(context, macroName);
    if (value == null) {
      return null;
    }
    return value.toString();
  }
};

代码示例来源:origin: oblac/jodd

public Object readValue(final String name) {
  String propertyName = name;
  if (type != null) {
    final int dotNdx = propertyName.indexOf('.');
    if (dotNdx == -1) {
      return value;
    }
    propertyName = propertyName.substring(dotNdx + 1);
  }
  return BeanUtil.declared.getProperty(value, propertyName);
}

代码示例来源:origin: oblac/jodd

public String parseWithBean(final String template, final Object context) {
    return super.parse(template, macroName -> {
      Object value = BeanUtil.declaredSilent.getProperty(context, macroName);

      if (value == null) {
        return null;
      }
      return value.toString();
    });
  }
}

代码示例来源:origin: oblac/jodd

protected Object resolveValueInSpecialCase(Object value, final String name) {
    String[] elements = StringUtil.splitc(name, '.');

    for (String element : elements) {
      value = BeanUtil.declaredSilent.getProperty(value, element);

      if (value instanceof List) {
        List list = (List) value;

        value = list.get(list.size() - 1);
      }
    }

    return value;
  }
}

代码示例来源:origin: oblac/jodd

/**
 * Returns ID value for given entity instance.
 */
public Object getIdValue(final E object) {
  final String propertyName = getIdPropertyName();
  return BeanUtil.declared.getProperty(object, propertyName);
}

代码示例来源:origin: oblac/jodd

/**
 * Reads property value and updates the DB.
 */
public DbSqlBuilder updateColumn(final Object entity, final String columnRef) {
  final Object value = BeanUtil.pojo.getProperty(entity, columnRef);
  return updateColumn(entity, columnRef, value);
}

代码示例来源:origin: oblac/jodd

public static boolean validate(final Object target, final Object value, final String fieldName) {
  if (value == null) {
    return true;
  }
  Object valueToCompare;
  try {
    valueToCompare = BeanUtil.pojo.getProperty(target, fieldName);
  } catch (BeanException bex) {
    throw new VtorException("Invalid value: " + fieldName, bex);
  }
  if (valueToCompare == null) {
    return false;
  }
  return value.equals(valueToCompare);
}

代码示例来源:origin: oblac/jodd

protected Object value(final String name, final PageContext pageContext) {
  String thisRef = BeanUtil.pojo.extractThisReference(name);
  Object value = ServletUtil.value(pageContext, thisRef);
  if (value == null) {
    return ServletUtil.value(pageContext, name);
  }
  if (thisRef.equals(name)) {
    return value;
  }
  String propertyName = name.substring(thisRef.length() + 1);
  return BeanUtil.declaredSilent.getProperty(value, propertyName);
}

代码示例来源:origin: oblac/jodd

@Test
void testSupplier_inMap() {
  Map map1 = new HashMap();
  Supplier<Map> mapSupplier = () -> map1;
  map1.put("qwe", "123");
  map1.put("asd", mapSupplier);
  assertEquals("123", BeanUtil.pojo.getProperty(map1, "qwe"));
  assertEquals("123", BeanUtil.pojo.getProperty(map1, "asd.qwe"));
}

代码示例来源:origin: oblac/jodd

@Test
void testSupplier_last() {
  Map map1 = new HashMap();
  Supplier<Map> mapSupplier = () -> map1;
  map1.put("qwe", "123");
  map1.put("asd", mapSupplier);
  assertEquals("123", BeanUtil.pojo.getProperty(map1, "qwe"));
  assertEquals(mapSupplier, BeanUtil.pojo.getProperty(map1, "asd"));
}

代码示例来源:origin: oblac/jodd

@Test
void testMapWithKeyWithADot() {
  Map innerMap = new HashMap();
  innerMap.put("zzz.xxx", "hey");
  Map map = new HashMap();
  map.put("foo.bar", innerMap);
  Object value = BeanUtil.pojo.getProperty(map, "[foo.bar]");
  assertNotNull(value);
  value = BeanUtil.pojo.getProperty(map, "[foo.bar].[zzz.xxx]");
  assertNotNull(value);
  assertEquals("hey", value.toString());
}

代码示例来源:origin: oblac/jodd

@Test
  void testSupplier_inBean() {
    Foo foo = new Foo();

    assertEquals(Integer.valueOf(13), BeanUtil.pojo.getProperty(foo, "bbb"));
    assertEquals(Integer.valueOf(13), BeanUtil.pojo.getProperty(foo, "aaa.bbb"));
  }
}

代码示例来源:origin: oblac/jodd

@Test
void testGetPropertySilent() {
  Bean bean = new Bean();
  assertNull(BeanUtil.silent.getProperty(bean, "miss"));
  assertNull(BeanUtil.silent.getProperty(bean, "datas[1]"));
  assertNull(BeanUtil.silent.getProperty(bean, "datas[a]"));
  assertNull(BeanUtil.silent.getProperty(bean.getMap(), "miss"));
}

代码示例来源:origin: oblac/jodd

/**
 * Updates property in the database by storing the current property value.
 */
public <E> E updateProperty(final E entity, final String name) {
  Object value = BeanUtil.declared.getProperty(entity, name);
  query(dbOom.entities().updateColumn(entity, name, value)).autoClose().executeUpdate();
  return entity;
}

代码示例来源:origin: oblac/jodd

@Test
void testIster() {
  Abean abean = new Abean();
  Boolean b = BeanUtil.pojo.getProperty(abean, "something");
  assertTrue(b);
  try {
    BeanUtil.pojo.getProperty(abean, "Something");
    fail("error");
  } catch (BeanException bex) {
    // ignore
  }
}

代码示例来源:origin: oblac/jodd

@Test
void testUppercase() {
  UppercaseBean ub = new UppercaseBean();
  try {
    BeanUtil.pojo.getProperty(ub, "URLaddress");
  } 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 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

@ParameterizedTest
@MethodSource("testdata_testAgainstSystemProperty")
void testAgainstSystemProperty(final String methodname, final String expected) {
  SystemInfo systemInfo = SystemUtil.info();
  final String actual = BeanUtil.declared.getProperty(systemInfo, methodname);
  // asserts
  assertNotNull(actual);
  assertEquals(expected, actual);
}

代码示例来源:origin: oblac/jodd

/**
 * Creates SELECT criteria for the entity matched by foreign key.
 * Foreign key is created by concatenating foreign table name and column name.
 */
public DbSqlBuilder findForeign(final Class entity, final Object value) {
  final String tableRef = createTableRefName(entity);
  final DbEntityDescriptor dedFk = entityManager.lookupType(value.getClass());
  final String tableName = dbOomConfig.getTableNames().convertTableNameToEntityName(dedFk.getTableName());
  final String columnName = dbOomConfig.getColumnNames().convertColumnNameToPropertyName(dedFk.getIdColumnName());
  final String fkColumn = uncapitalize(tableName) + capitalize(columnName);
  final Object idValue = BeanUtil.pojo.getProperty(value, dedFk.getIdPropertyName());
  return sql().$(SELECT).column(tableRef).$(FROM).table(entity, tableRef).$(WHERE).ref(tableRef, fkColumn).$(EQUALS).columnValue(idValue);
}

相关文章