當前位置: 首頁>>代碼示例>>Java>>正文


Java BeanWrapperImpl.getPropertyValue方法代碼示例

本文整理匯總了Java中org.springframework.beans.BeanWrapperImpl.getPropertyValue方法的典型用法代碼示例。如果您正苦於以下問題:Java BeanWrapperImpl.getPropertyValue方法的具體用法?Java BeanWrapperImpl.getPropertyValue怎麽用?Java BeanWrapperImpl.getPropertyValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.beans.BeanWrapperImpl的用法示例。


在下文中一共展示了BeanWrapperImpl.getPropertyValue方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testBeanWrapperCreatesNewNestedMaps

import org.springframework.beans.BeanWrapperImpl; //導入方法依賴的package包/類
@Test
public void testBeanWrapperCreatesNewNestedMaps() throws Exception {
	TargetWithNestedMap target = new TargetWithNestedMap();
	BeanWrapperImpl wrapper = new BeanWrapperImpl(target);
	wrapper.setAutoGrowNestedPaths(true);
	// For a nested map, you only have to get an element of it for it to be created
	wrapper.getPropertyValue("nested[foo]");
	// To decide what type to create for nested[foo] we need to look ahead and see
	// what the user is trying to bind it to, e.g. if nested[foo][bar] then it's a map
	wrapper.setPropertyValue("nested[foo]", new LinkedHashMap<String, Object>());
	// But it might equally well be a collection, if nested[foo][0]
	wrapper.setPropertyValue("nested[foo]", new ArrayList<Object>());
	// Then it would have to be actually bound to get the list to auto-grow
	wrapper.setPropertyValue("nested[foo][0]", "bar");
	assertThat(wrapper.getPropertyValue("nested[foo][0]")).isNotNull();
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:17,代碼來源:BindingPreparationTests.java

示例2: testBeanWrapperCreatesNewMaps

import org.springframework.beans.BeanWrapperImpl; //導入方法依賴的package包/類
@Test
public void testBeanWrapperCreatesNewMaps() throws Exception {
	TargetWithNestedMap target = new TargetWithNestedMap();
	BeanWrapperImpl wrapper = new BeanWrapperImpl(target);
	wrapper.setAutoGrowNestedPaths(true);
	// For a nested map, you only have to get an element of it for it to be created
	wrapper.getPropertyValue("nested[foo]");
	assertThat(wrapper.getPropertyValue("nested")).isNotNull();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:10,代碼來源:BindingPreparationTests.java

示例3: testBeanWrapperCreatesNewMapEntries

import org.springframework.beans.BeanWrapperImpl; //導入方法依賴的package包/類
@Test
public void testBeanWrapperCreatesNewMapEntries() throws Exception {
	TargetWithNestedMapOfBean target = new TargetWithNestedMapOfBean();
	BeanWrapperImpl wrapper = new BeanWrapperImpl(target);
	wrapper.setAutoGrowNestedPaths(true);
	// For a nested map, you only have to get an element of it for it to be created
	wrapper.getPropertyValue("nested[foo]");
	wrapper.setPropertyValue("nested[foo].foo", "bar");
	assertThat(wrapper.getPropertyValue("nested")).isNotNull();
	assertThat(wrapper.getPropertyValue("nested[foo]")).isNotNull();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:12,代碼來源:BindingPreparationTests.java

示例4: testBeanWrapperCreatesNewObjects

import org.springframework.beans.BeanWrapperImpl; //導入方法依賴的package包/類
@Test
public void testBeanWrapperCreatesNewObjects() throws Exception {
	TargetWithNestedObject target = new TargetWithNestedObject();
	BeanWrapperImpl wrapper = new BeanWrapperImpl(target);
	wrapper.setAutoGrowNestedPaths(true);
	// For a nested object, you have to set a property for it to be created
	wrapper.setPropertyValue("nested.foo", "bar");
	wrapper.getPropertyValue("nested");
	assertThat(wrapper.getPropertyValue("nested")).isNotNull();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:11,代碼來源:BindingPreparationTests.java

示例5: testBeanWrapperLists

import org.springframework.beans.BeanWrapperImpl; //導入方法依賴的package包/類
@Test
public void testBeanWrapperLists() throws Exception {
	TargetWithNestedMapOfListOfString target = new TargetWithNestedMapOfListOfString();
	BeanWrapperImpl wrapper = new BeanWrapperImpl(target);
	wrapper.setAutoGrowNestedPaths(true);
	TypeDescriptor descriptor = wrapper.getPropertyTypeDescriptor("nested");
	assertThat(descriptor.isMap()).isTrue();
	wrapper.getPropertyValue("nested[foo]");
	assertThat(wrapper.getPropertyValue("nested")).isNotNull();
	// You also need to bind to a value here
	wrapper.setPropertyValue("nested[foo][0]", "bar");
	wrapper.getPropertyValue("nested[foo][0]");
	assertThat(wrapper.getPropertyValue("nested[foo]")).isNotNull();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:15,代碼來源:BindingPreparationTests.java

示例6: convertFieldValueToString

import org.springframework.beans.BeanWrapperImpl; //導入方法依賴的package包/類
/**
 * Convert a field value to string
 * 
 * @param datePatterns
 * @param dateFormatters
 * @param conversionService
 * @param entityBean
 * @param entity
 * @param fieldName
 * @param unescapedFieldName
 * @return
 */
private static <T> String convertFieldValueToString(
        Map<String, Object> datePatterns,
        Map<String, SimpleDateFormat> dateFormatters,
        ConversionService conversionService, BeanWrapperImpl entityBean,
        T entity, String fieldName, String unescapedFieldName) {
    try {
        Object value = null;
        TypeDescriptor fieldDesc = entityBean
                .getPropertyTypeDescriptor(unescapedFieldName);
        TypeDescriptor strDesc = TypeDescriptor.valueOf(String.class);
        value = entityBean.getPropertyValue(unescapedFieldName);
        if (value == null) {
            return "";
        }

        // For dates
        if (Date.class.isAssignableFrom(value.getClass())
                || Calendar.class.isAssignableFrom(value.getClass())) {
            SimpleDateFormat formatter = getDateFormatter(datePatterns,
                    dateFormatters, entityBean.getWrappedClass(),
                    unescapedFieldName);
            if (formatter != null) {
                if (Calendar.class.isAssignableFrom(value.getClass())) {
                    // Gets Date instance as SimpleDateFormat
                    // doesn't works with Calendar
                    value = ((Calendar) value).getTime();
                }
                return formatter.format(value);
            }
        }
        String stringValue;
        // Try to use conversion service (uses field descrition
        // to handle field format annotations)
        if (conversionService.canConvert(fieldDesc, strDesc)) {
            stringValue = (String) conversionService.convert(value,
                    fieldDesc, strDesc);
            if (stringValue == null) {
                stringValue = "";
            }
        }
        else {
            stringValue = ObjectUtils.getDisplayString(value);
        }
        return stringValue;
    }
    catch (Exception ex) {
        LOGGER.error(String.format(
                "Error getting value of property [%s] in bean %s [%s]",
                unescapedFieldName,
                entity.getClass().getSimpleName(),
                org.apache.commons.lang3.ObjectUtils.firstNonNull(
                        entity.toString(), "{unknow}")), ex);
        return "";
    }
}
 
開發者ID:gvSIGAssociation,項目名稱:gvnix1,代碼行數:68,代碼來源:DatatablesUtils.java

示例7: convertFieldValueToString

import org.springframework.beans.BeanWrapperImpl; //導入方法依賴的package包/類
/**
 * Convert a field value to string
 * 
 * @param datePatterns
 * @param dateFormatters
 * @param conversionService
 * @param entityBean
 * @param entity
 * @param fieldName
 * @param unescapedFieldName
 * @return
 */
private <T> String convertFieldValueToString(
        Map<String, Object> datePatterns,
        Map<String, SimpleDateFormat> dateFormatters,
        BeanWrapperImpl entityBean, T entity, String fieldName,
        String unescapedFieldName) {
    try {
        Object value = null;
        TypeDescriptor fieldDesc = entityBean
                .getPropertyTypeDescriptor(unescapedFieldName);
        TypeDescriptor strDesc = TypeDescriptor.valueOf(String.class);
        value = entityBean.getPropertyValue(unescapedFieldName);
        if (value == null) {
            return "";
        }

        // For dates
        if (Date.class.isAssignableFrom(value.getClass())
                || Calendar.class.isAssignableFrom(value.getClass())) {
            SimpleDateFormat formatter = getDateFormatter(datePatterns,
                    dateFormatters, entityBean.getWrappedClass(),
                    unescapedFieldName);
            if (formatter != null) {
                if (Calendar.class.isAssignableFrom(value.getClass())) {
                    // Gets Date instance as SimpleDateFormat
                    // doesn't works with Calendar
                    value = ((Calendar) value).getTime();
                }
                return formatter.format(value);
            }
        }
        String stringValue;
        // Try to use conversion service (uses field descrition
        // to handle field format annotations)
        if (conversionService.canConvert(fieldDesc, strDesc)) {
            stringValue = (String) conversionService.convert(value,
                    fieldDesc, strDesc);
            if (stringValue == null) {
                stringValue = "";
            }
        }
        else {
            stringValue = ObjectUtils.getDisplayString(value);
        }
        return stringValue;
    }
    catch (Exception ex) {
        LOGGER.error(String.format(
                "Error getting value of property [%s] in bean %s [%s]",
                unescapedFieldName,
                entity.getClass().getSimpleName(),
                org.apache.commons.lang3.ObjectUtils.firstNonNull(
                        entity.toString(), "{unknow}")), ex);
        return "";
    }
}
 
開發者ID:gvSIGAssociation,項目名稱:gvnix1,代碼行數:68,代碼來源:DatatablesUtilsBeanImpl.java


注:本文中的org.springframework.beans.BeanWrapperImpl.getPropertyValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。