本文整理匯總了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;
}
}
}