本文整理汇总了Java中org.apache.commons.beanutils.BeanUtils.cloneBean方法的典型用法代码示例。如果您正苦于以下问题:Java BeanUtils.cloneBean方法的具体用法?Java BeanUtils.cloneBean怎么用?Java BeanUtils.cloneBean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.beanutils.BeanUtils
的用法示例。
在下文中一共展示了BeanUtils.cloneBean方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProtectedOxTrustApplicationConfiguration
import org.apache.commons.beanutils.BeanUtils; //导入方法依赖的package包/类
private String getProtectedOxTrustApplicationConfiguration(ApplicationConfiguration oxTrustApplicationConfiguration) {
try {
ApplicationConfiguration resultOxTrustApplicationConfiguration = (ApplicationConfiguration) BeanUtils.cloneBean(oxTrustApplicationConfiguration);
resultOxTrustApplicationConfiguration.setSvnConfigurationStorePassword(HIDDEN_PASSWORD_TEXT);
resultOxTrustApplicationConfiguration.setKeystorePassword(HIDDEN_PASSWORD_TEXT);
resultOxTrustApplicationConfiguration.setIdpSecurityKeyPassword(HIDDEN_PASSWORD_TEXT);
resultOxTrustApplicationConfiguration.setIdpBindPassword(HIDDEN_PASSWORD_TEXT);
resultOxTrustApplicationConfiguration.setMysqlPassword(HIDDEN_PASSWORD_TEXT);
resultOxTrustApplicationConfiguration.setCaCertsPassphrase(HIDDEN_PASSWORD_TEXT);
resultOxTrustApplicationConfiguration.setOxAuthClientPassword(HIDDEN_PASSWORD_TEXT);
return jsonService.objectToJson(resultOxTrustApplicationConfiguration);
} catch (Exception ex) {
log.error("Failed to prepare JSON from ApplicationConfiguration: '{0}'", ex, oxTrustApplicationConfiguration);
}
return null;
}
示例2: edit
import org.apache.commons.beanutils.BeanUtils; //导入方法依赖的package包/类
@PostMapping("/{id}/edit")
public String edit(@PathVariable String id, @RequestParam(required = false) String title,
@RequestParam(required = false) String body, @RequestParam(required = false) String tags,
HttpServletRequest req) {
Post showPost = pc.read(id);
Profile authUser = utils.getAuthUser(req);
if (!utils.canEdit(showPost, authUser) || showPost == null) {
return "redirect:" + req.getRequestURI();
}
Post beforeUpdate = null;
try {
beforeUpdate = (Post) BeanUtils.cloneBean(showPost);
} catch (Exception ex) {
logger.error(null, ex);
}
if (!StringUtils.isBlank(title) && title.length() > 10) {
showPost.setTitle(title);
}
if (!StringUtils.isBlank(body)) {
showPost.setBody(body);
}
if (!StringUtils.isBlank(tags) && showPost.isQuestion()) {
showPost.setTags(Arrays.asList(StringUtils.split(tags, ",")));
}
//note: update only happens if something has changed
if (!showPost.equals(beforeUpdate)) {
showPost.setLasteditby(authUser.getId());
showPost.setLastedited(System.currentTimeMillis());
showPost.update();
utils.addBadgeOnceAndUpdate(authUser, Badge.EDITOR, true);
}
return "redirect:" + showPost.getPostLink(false, false);
}
示例3: cloneBean
import org.apache.commons.beanutils.BeanUtils; //导入方法依赖的package包/类
/**
* 复制一个对象并返回,属于浅度克隆,对象所属类必须符合JavaBean规范
*
* @param bean 被复制的对象
* @return 返回一个被复制对象的一个副本
*/
@SuppressWarnings("unchecked")
public static <T extends Object> T cloneBean(T bean) {
try {
T newBean = (T) BeanUtils.cloneBean(bean);
return newBean;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例4: cloneCDR
import org.apache.commons.beanutils.BeanUtils; //导入方法依赖的package包/类
public CDR cloneCDR(){
try {
return (CDR) BeanUtils.cloneBean(this);
} catch (IllegalAccessException | InvocationTargetException | InstantiationException | NoSuchMethodException e) {
e.printStackTrace();
}
return null;
}
示例5: cloneBean
import org.apache.commons.beanutils.BeanUtils; //导入方法依赖的package包/类
/**
* Clone bean.
*
* @param <T>
* the generic type
* @param bean
* the bean
* @return the t
*/
public static <T> T cloneBean(final Object bean) {
try {
return (T) BeanUtils.cloneBean(bean);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
}