本文整理汇总了Java中org.springframework.beans.BeanWrapperImpl.getPropertyTypeDescriptor方法的典型用法代码示例。如果您正苦于以下问题:Java BeanWrapperImpl.getPropertyTypeDescriptor方法的具体用法?Java BeanWrapperImpl.getPropertyTypeDescriptor怎么用?Java BeanWrapperImpl.getPropertyTypeDescriptor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.beans.BeanWrapperImpl
的用法示例。
在下文中一共展示了BeanWrapperImpl.getPropertyTypeDescriptor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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
示例2: 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 "";
}
}
示例3: 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 "";
}
}