• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java LazyDynaBean类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.commons.beanutils.LazyDynaBean的典型用法代码示例。如果您正苦于以下问题:Java LazyDynaBean类的具体用法?Java LazyDynaBean怎么用?Java LazyDynaBean使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LazyDynaBean类属于org.apache.commons.beanutils包,在下文中一共展示了LazyDynaBean类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: copy

import org.apache.commons.beanutils.LazyDynaBean; //导入依赖的package包/类
private void copy(final Directory directory, final Map<String, Object> metadata) {
    final TagDescriptor<?> descriptor = MetadataHelper.getDescriptor(directory);

    final LazyDynaClass directoryClass = new LazyDynaClass(directory.getName(), null, directory.getTags()
            .parallelStream()
            .map(t -> new DynaProperty(t.getTagName().replaceAll(NON_WORD_CHARS, ""), String.class))
            .toArray(DynaProperty[]::new));
    directoryClass.setReturnNull(true);

    final DynaBean directoryMetadata = new LazyDynaBean(directoryClass);
    directory.getTags().stream().forEach(t -> directoryMetadata.set(
            t.getTagName().replaceAll(NON_WORD_CHARS, ""),
            descriptor.getDescription(t.getTagType())
    ));
    metadata.put(directory.getName().replaceAll(NON_WORD_CHARS, ""), directoryMetadata);
}
 
开发者ID:edouardhue,项目名称:comeon,代码行数:17,代码来源:PictureReader.java


示例2: setUp

import org.apache.commons.beanutils.LazyDynaBean; //导入依赖的package包/类
@Override
     protected void setUp() throws Exception {
         target = new LazyDynaBean();

final Fixture decorated = context.mock(Fixture.class);

context.checking(new Expectations()
{{
	between(0, 2).of(decorated).canCheck("property");
	will(returnValue(false));
	between(0, 2).of(decorated).canSend("property");
	will(returnValue(false));
	between(0, 2).of(decorated).getTarget();
	will(returnValue(target));
}});
         fixture = new DynaBeanFixture(decorated);
     }
 
开发者ID:strator-dev,项目名称:greenpepper,代码行数:18,代码来源:DynaBeanFixtureTest.java


示例3: sendMailVelocity

import org.apache.commons.beanutils.LazyDynaBean; //导入依赖的package包/类
/**
 * Velocity 模板发送邮件 html 格式
 *
 * @param to
 * @param subject
 * @throws javax.mail.MessagingException
 */
public void sendMailVelocity(String from ,String[] to, String subject) throws MessagingException {

    //如果不是 html 格式,修改为  SimpleMailMessage
    MimeMessage message = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message, true, StandardCharsets.UTF_8.toString());

    /**
     *邮件内容
     */
    helper.setFrom(from);
    helper.setTo(to);
    helper.setSubject(subject);

    //模板内容
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("firstName", "Yashwant");
    model.put("lastName", "Chavan");
    model.put("location", "china");
    //创建动态 bean
    DynaBean dynaBean = new LazyDynaBean();
    dynaBean.set("name", "It is name"); //simple
    dynaBean.set("gender", new Integer(1));  //simple
    //设置 bean 属性

    // Velocity 工具类,实例可以直接放入 map ,在模板文件中直接使用
    // 如日期格式化 $dateTool.format("yyyy-MM-dd",$info.issueTime)
    DateTool dateTool = new DateTool();//日期工具
    NumberTool numberTool = new NumberTool();//数字工具
    model.put("dateTool",dateTool);
    model.put("numberTool",numberTool);

    model.put("bean", dynaBean);
    String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "./templates/velocity_template_email-newsletter.vm", StandardCharsets.UTF_8.toString(), model);
    helper.setText(text, true);

    mailSender.send(message);
}
 
开发者ID:h819,项目名称:spring-boot,代码行数:45,代码来源:SpringMailService.java


示例4: testDynaBeanController

import org.apache.commons.beanutils.LazyDynaBean; //导入依赖的package包/类
@RequestMapping(value = "/website/test.html")
public String testDynaBeanController(Model model) {

    //创建动态 bean
    DynaBean dynaBean = new LazyDynaBean();

    //字符串属性,通过属性名 name 调用
    dynaBean.set("name", "Peter Collinson"); //simple

    //数字属性 ,通过属性名 gender 调用
    dynaBean.set("gender", new Integer(1));  //simple

    //bean 属性,通过属性名 bean 调用
    UserBean beanExample = new UserBean();
    beanExample.setName("name string."); //simple
    dynaBean.set("bean", beanExample);

    //map 属性,通过 customer 和 title 调用
    dynaBean.set("customer", "title", "Mr");      // mapped
    dynaBean.set("customer", "surname", "Smith"); // mapped

    //可以指定属性顺序,通过 address 和 顺序号调用
    /**
     * 此方式无法通过 jstl 调用,不使用
     * */
    dynaBean.set("address", 0, "addressLine1");     // indexed
    dynaBean.set("address", 1, "addressLine2");     // indexed
    dynaBean.set("address", 2, "addressLine3");     // indexed

    //其他用法
    /**
     * 可以转换成  map , 用法同 LazyDynaBean
     */
    LazyDynaMap dynaMapBean = new LazyDynaMap();
    dynaMapBean.set("name", "Peter Collinson"); //simple;
    Map myMap = dynaMapBean.getMap();   // retrieve the Map


    //传递到前端
    model.addAttribute("test", dynaBean);
    return "2760/jsp/test";

    /**
     * 前端调用
     */
    //页面 jstl 读取,不需要,用引入任何类,仅引入 jstl 标签即可使用
    //注意,使用 map 这个关键字
    //http://commons.apache.org/proper/commons-beanutils/apidocs/org/apache/commons/beanutils/BasicDynaBean.html
    //官方 doc 中,getMap() 方法解释处有说明

    /**
       调用代码 : test 为 bean 名称,如果是字符串 $ {map.name} 即可
     $ {test.map.name} <br />
     $ {test.map.gender} <br />
     $ {test.map.bean.name} <br />
     $ {test.map.customer.title} <br />
     $ {test.map.customer.surname} <br />

     */

    //http://www.programgo.com/article/85353617047/
}
 
开发者ID:h819,项目名称:spring-boot,代码行数:63,代码来源:DynaBeansExample.java


示例5: setUp

import org.apache.commons.beanutils.LazyDynaBean; //导入依赖的package包/类
protected void setUp() throws Exception {
    DynaProperty name = new DynaProperty("name", int.class);
    bean = new LazyDynaBean(new LazyDynaClass("target", new DynaProperty[] { name } ));
}
 
开发者ID:strator-dev,项目名称:greenpepper,代码行数:5,代码来源:DynaPropertyWriterTest.java


示例6: testDynaBeans

import org.apache.commons.beanutils.LazyDynaBean; //导入依赖的package包/类
@Test
public void testDynaBeans() throws Exception
{
	// for usage, see
	// http://commons.apache.org/proper/commons-beanutils/javadocs/v1.9.2/apidocs/org/apache/commons/beanutils/package-summary.html#package_description

	final DynaBean dynaBean = new LazyDynaBean(); // Create LazyDynaBean
	final MutableDynaClass dynaClass = (MutableDynaClass) dynaBean
			.getDynaClass(); // get DynaClass

	dynaClass.add("amount", java.lang.Integer.class); // add property
	dynaClass.add("myMap", java.util.TreeMap.class); // add mapped property

	final DynaBean employee = dynaClass.newInstance();

	// TODO experiment with Jackson's AnnotationIntrospector to annotate
	// DynaBean#get(...) method with @JsonAnyGetter and #set(...) method
	// with @JsonAnySetter

	employee.set("address", new HashMap<String, String>());
	employee.set("activeEmployee", Boolean.FALSE);
	employee.set("firstName", "Fred");
	employee.set("lastName", "Flintstone");

	LOG.trace("Employee: " + JsonUtil.toPrettyJSON(employee));

	// set all <activeEmployee> attribute values to <true>
	final BeanPropertyValueChangeClosure closure = new BeanPropertyValueChangeClosure(
			"activeEmployee", Boolean.TRUE);

	final Collection<?> employees = Collections.singleton(employee);
	LOG.trace("Mutated employees: " + JsonUtil.toPrettyJSON(employees));

	// update the Collection
	CollectionUtils.forAllDo(employees, closure);

	// filter for beans with <activeEmployee> set to <false>
	final BeanPropertyValueEqualsPredicate predicate = new BeanPropertyValueEqualsPredicate(
			"lastName", "Flintstone");

	// filter the Collection
	CollectionUtils.filter(employees, predicate);
	LOG.trace("Filtered employees: " + JsonUtil.toPrettyJSON(employees));
}
 
开发者ID:krevelen,项目名称:coala,代码行数:45,代码来源:DynaBeanTest.java


示例7: newDynaBean

import org.apache.commons.beanutils.LazyDynaBean; //导入依赖的package包/类
/**
 * 使用 <code>valueMap</code> 来构造一个 DynaBean.
 * 
 * <h3>说明:</h3>
 * <blockquote>
 * <ol>
 * <li>一般情况下,你可能不需要使用这个方法</li>
 * <li>很适合那种属性值数量不确定,并且又不想在页面使用map来渲染的地方,比如制作多维度的图表</li>
 * <li>程序内部,默认使用的是 {@link org.apache.commons.beanutils.LazyDynaClass}</li>
 * <li>不需要先创建一个期望的数据结构DynaClass,就能向{@link LazyDynaBean}中填充我们任意想填充的数据。</li>
 * <li>{@link LazyDynaBean}内部会根据我们填充进的数据(即使是一个map中的一个key-value pair),创建metadata的。</li>
 * </ol>
 * </blockquote>
 * 
 * <h3>示例:</h3>
 * 
 * <blockquote>
 * 
 * <pre class="code">
 * DynaBean newDynaBean = BeanUtil.newDynaBean(
 *                 toMap(//
 *                                 Pair.of("address", (Object) newHashMap()),
 *                                 Pair.of("firstName", (Object) "Fred"),
 *                                 Pair.of("lastName", (Object) "Flintstone")));
 * LOGGER.debug(JsonUtil.format(newDynaBean));
 * </pre>
 * 
 * <b>返回:</b>
 * 
 * <pre class="code">
 * {
 * "address": {},
 * "firstName": "Fred",
 * "lastName": "Flintstone"
 * }
 * </pre>
 * 
 * </blockquote>
 *
 * @param valueMap
 *            the value map
 * @return the dyna bean
 * @throws NullPointerException
 *             如果 <code>valueMap</code> 是null,或者 <code>valueMap</code>中有key是null
 * @throws IllegalArgumentException
 *             如果<code>valueMap</code>中有key是empty
 * @see org.apache.commons.beanutils.LazyDynaBean
 * @since 1.8.1
 */
public static DynaBean newDynaBean(Map<String, ?> valueMap){
    Validate.notNull(valueMap, "valueMap can't be null!");

    LazyDynaBean lazyDynaBean = new LazyDynaBean();
    for (Map.Entry<String, ?> entry : valueMap.entrySet()){
        Validate.notBlank(entry.getKey(), "entry.getKey() can't be blank!");
        lazyDynaBean.set(entry.getKey(), entry.getValue());
    }
    return lazyDynaBean;
}
 
开发者ID:venusdrogon,项目名称:feilong-core,代码行数:60,代码来源:BeanUtil.java


示例8: LazyValidatorForm

import org.apache.commons.beanutils.LazyDynaBean; //导入依赖的package包/类
/**
 * Default Constructor which creates a <code>LazyDynaBean</code> to <i>back</i>
 * this form.
 */
public LazyValidatorForm() {
    super(new LazyDynaBean());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:LazyValidatorForm.java


示例9: getMap

import org.apache.commons.beanutils.LazyDynaBean; //导入依赖的package包/类
/**
* <p>Return the <code>Map</code> containing the property values.</p>
*
* <p>Provided so that properties can be access using JSTL.</p>
*/
public Map getMap() {
    return ((LazyDynaBean)dynaBean).getMap();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:LazyValidatorForm.java


示例10: newIndexedBean

import org.apache.commons.beanutils.LazyDynaBean; //导入依赖的package包/类
/**
* <p>Creates new <code>DynaBean</code> instances to populate
*    an 'indexed' property of beans - defaults to <code>LazyDynaBean</code>
*    type.</p>
*
* <p>Override this method if you require a different type of
*    <code>DynaBean</code>.</p>
*/
protected DynaBean newIndexedBean(String name) {
    return new LazyDynaBean();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:LazyValidatorForm.java


示例11: LazyValidatorForm

import org.apache.commons.beanutils.LazyDynaBean; //导入依赖的package包/类
/**
 * Default Constructor which creates a <code>LazyDynaBean</code> to
 * <i>back</i> this form.
 */
public LazyValidatorForm() {
    super(new LazyDynaBean());
}
 
开发者ID:SonarSource,项目名称:sonar-scanner-maven,代码行数:8,代码来源:LazyValidatorForm.java


示例12: getMap

import org.apache.commons.beanutils.LazyDynaBean; //导入依赖的package包/类
/**
 * <p>Return the <code>Map</code> containing the property values.</p>
 *
 * <p>Provided so that properties can be access using JSTL.</p>
 */
public Map getMap() {
    return ((LazyDynaBean) dynaBean).getMap();
}
 
开发者ID:SonarSource,项目名称:sonar-scanner-maven,代码行数:9,代码来源:LazyValidatorForm.java


示例13: newIndexedBean

import org.apache.commons.beanutils.LazyDynaBean; //导入依赖的package包/类
/**
 * <p>Creates new <code>DynaBean</code> instances to populate an 'indexed'
 * property of beans - defaults to <code>LazyDynaBean</code> type.</p>
 *
 * <p>Override this method if you require a different type of
 * <code>DynaBean</code>.</p>
 */
protected DynaBean newIndexedBean(String name) {
    return new LazyDynaBean();
}
 
开发者ID:SonarSource,项目名称:sonar-scanner-maven,代码行数:11,代码来源:LazyValidatorForm.java



注:本文中的org.apache.commons.beanutils.LazyDynaBean类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SetSplitState类代码示例发布时间:2022-05-23
下一篇:
Java SslContextFactory类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap