本文整理汇总了Java中org.apache.commons.beanutils.PropertyUtils.describe方法的典型用法代码示例。如果您正苦于以下问题:Java PropertyUtils.describe方法的具体用法?Java PropertyUtils.describe怎么用?Java PropertyUtils.describe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.beanutils.PropertyUtils
的用法示例。
在下文中一共展示了PropertyUtils.describe方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apiMessageMassPreview
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
* 群发消息预览
*
* @param towxname
* @param msg
* @return
* @throws IllegalAccessException
* @throws InvocationTargetException
* @throws NoSuchMethodException
* @throws ClientProtocolException
* @throws URISyntaxException
* @throws IOException
* @throws AccessTokenFailException
*/
public BaseResp apiMessageMassPreview(String towxname, MassMsg msg)
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClientProtocolException,
URISyntaxException, IOException, AccessTokenFailException {
MpAccessToken token = mpApi.apiToken();
String path = String.format("/message/mass/preview?access_token=%s", token.getAccessToken());
Map<String, Object> reqMap = PropertyUtils.describe(msg);
reqMap.put("towxname", towxname);
String respText = HttpUtil.post(mpApi.config.getApiHttps(), path, reqMap);
BaseResp resp = new Gson().fromJson(respText, BaseResp.class);
if (mpApi.log.isInfoEnabled()) {
mpApi.log.info(String.format("apiMessageMassDelete %s", new Gson().toJson(resp)));
}
return resp;
}
示例2: format
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
@Override
public String format(ApiModule apiModule) {
VelocityTemplater templater = new VelocityTemplater("org/treeleafj/xdoc/spring/format/api.vm");
for (ApiAction apiAction : apiModule.getApiActions()) {
SpringApiAction saa = (SpringApiAction) apiAction;
if (saa.isJson() && StringUtils.isNotBlank(saa.getRespbody())) {
saa.setRespbody(JsonFormatUtils.formatJson(saa.getRespbody()));
}
}
try {
Map<String, Object> map = PropertyUtils.describe(apiModule);
return templater.parse(map);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例3: toMap
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
* 将一个JavaBean对象的所有属性封装在Map中并返回,
* 注意只能将拥有Getter方法的属性才能取出并封装到Map中
*
* @param bean 需要转换的Bean对象
* @return 返回一个Map , 失败返回null
*/
public static <T extends Object> Map<String, Object> toMap(T bean) {
Map<String, Object> map = null;
try {
map = PropertyUtils.describe(bean);
map.remove("class");
StringBuilder methodName = new StringBuilder("get");
for (String property : map.keySet()) {
methodName.delete(3, methodName.length()).append(property.substring(0, 1).toUpperCase())
.append(property.substring(1));
Object o = MethodUtils.invokeMethod(bean, methodName.toString(), null);
map.put(property, o);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return map;
}
示例4: calculateBeanPropertyData
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private Object calculateBeanPropertyData(String[] columnNames, Map<String, Object> map) throws Exception {
Object obj = map.get(columnNames[0]);
if(obj==null){
return null;
}
if (columnNames.length == 1) {
return obj;
} else if (columnNames.length == 2) {
return BeanUtils.getBeanProperty(obj, columnNames[1]);
} else {
Map subMap = PropertyUtils.describe(obj);
List<String> list = new ArrayList<String>();
int i = 1;
while (i < columnNames.length) {
list.add(columnNames[i]);
i++;
}
String[] array = list.toArray(new String[list.size()]);
return calculateBeanPropertyData(array, subMap);
}
}
示例5: getValue
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
* Dtoオブジェクトから値を取り出す. プロパティにDtoオブジェクトがある場合、KEY名を「プロパティ名.子のプロパティ名」とすること.
* (何階層でも対応可能)
* @param object
* Dtoオブジェクト.
* @param key
* フィールドインスタンス名.
* @return keyで指定されたフィールドの値.
* @throws IllegalAccessException プロパティへの不正アクセス
* @throws InvocationTargetException プロパティ取得メソッド起動失敗
* @throws NoSuchMethodException プロパティに対応するメソッドが無い
*/
public static Object getValue(Object object, String key) throws IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
Map<?, ?> map = PropertyUtils.describe(object);
if (key.indexOf(".") > -1) {
Object bean = map.get(key.substring(0, key.indexOf(".")));
if (bean != null) {
return getValue(bean, key.substring(key.indexOf(".") + 1));
} else {
return null;
}
} else {
return map.get(key);
}
}
示例6: serialize
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
@Override
public byte[] serialize(ServiceInstance<RpcPayload> instance)
throws Exception {
Map<String, Object> map = PropertyUtils.describe(instance);
map.put("uriSpec", this.serializeUriSpec(instance.getUriSpec()));
map.remove("class");
String jsonStr = this.toJson(map);
return jsonStr.getBytes();
}
示例7: beanToMap
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
/**
* 将javaBean对象转为Map
*
* @param bean
* @return Map
*/
public static Map<String, Object> beanToMap(Object bean) {
try {
return PropertyUtils.describe(bean);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例8: toParameterMap
import org.apache.commons.beanutils.PropertyUtils; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
protected static Map toParameterMap(Object parameter) {
if (parameter instanceof Map) {
return (Map) parameter;
} else {
try {
return PropertyUtils.describe(parameter);
} catch (Exception e) {
ReflectionUtils.handleReflectionException(e);
return null;
}
}
}