本文整理汇总了Java中org.apache.commons.beanutils.BeanUtils.describe方法的典型用法代码示例。如果您正苦于以下问题:Java BeanUtils.describe方法的具体用法?Java BeanUtils.describe怎么用?Java BeanUtils.describe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.beanutils.BeanUtils
的用法示例。
在下文中一共展示了BeanUtils.describe方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConditions
import org.apache.commons.beanutils.BeanUtils; //导入方法依赖的package包/类
protected Map getConditions(Object param) throws IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
// 静态条件部分
Map props = BeanUtils.describe(param);
// new 动态条件部分 add by hekun
if (param instanceof DBQueryParam) {
DBQueryParam listVO = (DBQueryParam) param;
Map queryConditions = listVO.getQueryConditions();
if (queryConditions != null && queryConditions.size() > 0) {
// 将静态条件加入动态条件中,重复的动态条件及其值将被覆盖。
for (Iterator keys = props.keySet().iterator(); keys.hasNext(); ) {
String key = (String) keys.next();
Object value = props.get(key);
if (key.startsWith("_") && value != null)
queryConditions.put(key, value);
}
props = queryConditions;
}
}
return props;
}
示例2: toString
import org.apache.commons.beanutils.BeanUtils; //导入方法依赖的package包/类
public String toString()
{
try
{
StringBuffer sb = new StringBuffer( "{" );
Map properties = BeanUtils.describe( this );
for ( Iterator it = properties.keySet().iterator(); it.hasNext(); )
{
Object key = it.next();
Object value = properties.get( key );
sb.append( key.toString() ).append( "=" ).append( value != null ? value.toString() : null ).append( it.hasNext() ? ", " : "") ;
}
sb.append( "}" );
return sb.toString();
}
catch( Exception exc )
{
exc.printStackTrace();
return super.toString();
}
}
示例3: addInnerQueryString
import org.apache.commons.beanutils.BeanUtils; //导入方法依赖的package包/类
/**
* 拼接URL,参数从obj中通过反射取得。
*
* @param url
* URL
* @param obj
* 对象
* @return 拼接后的URL
*/
public static String addInnerQueryString(String url, Object obj) {
List<String> names = new ArrayList<>();
List<Object> values = new ArrayList<>();
try {
Map<String, String> properties = BeanUtils.describe(obj);
for (Map.Entry<String, String> entry : properties.entrySet()) {
String name = entry.getKey();
if ("class".equals(name)) {
continue;
}
names.add(name);
values.add(entry.getValue());
}
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
}
return addQueryString(url, names.toArray(new String[names.size()]), values.toArray(new Object[values.size()]));
}
示例4: initailizeTestValuesToInsert
import org.apache.commons.beanutils.BeanUtils; //导入方法依赖的package包/类
@Override
protected Map<String, Object> initailizeTestValuesToInsert(List<String> testColumns, Object entityToInsert) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
logger.info("Starting method: initailizeTestValuesToInsert");
for(String testColumn : testColumns){
logger.info("Testing columns: " + testColumn);
}
Map<String, Object> valuesToInsert = new HashMap<String, Object>();
Map<String, String> fieldValues = BeanUtils.describe(entityToInsert);
for(Map.Entry<String, String> entry : fieldValues.entrySet()){
logger.info("Preparing entry set entry of: " + entry.getKey() + " : " + entry.getValue());
}
for (String testColumnName : testColumns){
String propertyName = transformSqlColumnNamesToJavaPropertyName(testColumnName);
String fieldValue = fieldValues.get(propertyName);
logger.info("Setting field value: " + fieldValue + " from field: " + propertyName + " for column: " + testColumnName);
if( fieldValues.get(propertyName) != null) {
valuesToInsert.put(testColumnName, fieldValues.get(propertyName));
}else{
valuesToInsert.put(testColumnName, ((SkuEntity) entityToInsert).getSkuVendor().getVendorKey());
}
}
return valuesToInsert;
}
示例5: initailizeTestValuesToInsert
import org.apache.commons.beanutils.BeanUtils; //导入方法依赖的package包/类
@Override
protected Map<String, Object> initailizeTestValuesToInsert(List<String> testColumns, Object entityToInsert) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
Map<String, Object> valuesToInsert = new HashMap<String, Object>();
Map<String, String> fieldValues = BeanUtils.describe(entityToInsert);
for (String testColumnName : testColumns){
valuesToInsert.put(testColumnName, fieldValues.get(transformSqlColumnNamesToJavaPropertyName(testColumnName)));
}
return valuesToInsert;
}
示例6: po2Map
import org.apache.commons.beanutils.BeanUtils; //导入方法依赖的package包/类
/**
* 将po对象中有属性和值转换成map
*
* @param po
* @return
*/
public static Map po2Map(Object po) {
Map poMap = new HashMap();
Map map = new HashMap();
try {
map = BeanUtils.describe(po);
} catch (Exception ex) {
}
Object[] keyArray = map.keySet().toArray();
for (int i = 0; i < keyArray.length; i++) {
String str = keyArray[i].toString();
if (str != null && !str.equals("class")) {
if (map.get(str) != null) {
poMap.put(str, map.get(str));
}
}
}
Method[] ms =po.getClass().getMethods();
for(Method m:ms){
String name = m.getName();
if(name.startsWith("get")||name.startsWith("is")){
if(m.getAnnotation(NotDbField.class)!=null||m.getAnnotation(PrimaryKeyField.class)!=null){
poMap.remove(getFieldName(name));
}
}
}
/**
* 如果此实体为动态字段实体,将动态字段加入
*/
if(po instanceof DynamicField){
DynamicField dynamicField = (DynamicField) po;
Map fields = dynamicField.getFields();
poMap.putAll(fields);
}
return poMap;
}
示例7: toString
import org.apache.commons.beanutils.BeanUtils; //导入方法依赖的package包/类
@Override
public String toString() {
try {
Map<String, String> properties = BeanUtils.describe(this);
properties.remove("class");
return properties.toString();
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
return super.toString();
}
}
示例8: po2Map
import org.apache.commons.beanutils.BeanUtils; //导入方法依赖的package包/类
/**
* 将po对象中有属性和值转换成map
*
* @param po
* @return
*/
public static Map po2Map(Object po) {
Map poMap = new HashMap();
Map map = new HashMap();
try {
map = BeanUtils.describe(po);
} catch (Exception ex) {
}
Object[] keyArray = map.keySet().toArray();
for (int i = 0; i < keyArray.length; i++) {
String str = keyArray[i].toString();
if (str != null && !str.equals("class")) {
if (map.get(str) != null) {
poMap.put(str, map.get(str));
}
}
}
Method[] ms =po.getClass().getMethods();
/*for(Method m:ms){
String name = m.getName();
/* if(name.startsWith("get")||name.startsWith("is")){
if(m.getAnnotation(NotDbField.class)!=null||m.getAnnotation(PrimaryKeyField.class)!=null){
poMap.remove(getFieldName(name));
}
}
}
/**
* 如果此实体为动态字段实体,将动态字段加入
*/
/*if(po instanceof DynamicField){
DynamicField dynamicField = (DynamicField) po;
Map fields = dynamicField.getFields();
poMap.putAll(fields);
}*/
return poMap;
}
示例9: process
import org.apache.commons.beanutils.BeanUtils; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void process(SysLog sysLog) {
Map map = null;
try {
map = BeanUtils.describe(sysLog);
map.remove("class");
} catch (Exception e) {
e.printStackTrace();
}
Record record = new Record();
record.setColumns(map);
System.out.println(record);
// Db.save("syslog", record);
}