Commons BeanUtils 中对Map的操作

<h1>
    <span class="link_title"><a href="/linminqin/article/details/6697303">
    Commons BeanUtils 中对Map的操作            
    </a></span>
</h1>
    <div class="article_manage clearfix">
    <div class="article_l">
        <span class="link_categories">
        标签:
          <a href="http://www.csdn.net/tag/bean" target="_blank" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_tag']);">bean</a><a href="http://www.csdn.net/tag/integer" target="_blank" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_tag']);">integer</a>
        </span>
    </div>
    <div class="article_r">
        <span class="link_postdate">2011-08-18 10:32</span>
        <span class="link_view" title="阅读次数">3966人阅读</span>
        <span class="link_comments" title="评论次数"> <a href="#comments" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_pinglun'])">评论</a>(0)</span>
        <span class="link_collect tracking-ad" data-mod="popu_171"> <a href="javascript:void(0);" onclick="javascript:collectArticle('Commons+BeanUtils+%e4%b8%ad%e5%af%b9Map%e7%9a%84%e6%93%8d%e4%bd%9c','6697303');return false;" title="收藏" target="_blank">收藏</a></span>
         <span class="link_report"> <a href="#report" onclick="javascript:report(6697303,2);return false;" title="举报">举报</a></span>

    </div>
</div>
<div class="embody" style="display:none" id="embody">
    <span class="embody_t">本文章已收录于:</span>
    <div class="embody_c" id="lib" value="{&quot;err&quot;:0,&quot;msg&quot;:&quot;ok&quot;,&quot;data&quot;:[]}"></div>
</div>
<style type="text/css">        
        .embody{
            padding:10px 10px 10px;
            margin:0 -20px;
            border-bottom:solid 1px #ededed;                
        }
        .embody_b{
            margin:0 ;
            padding:10px 0;
        }
        .embody .embody_t,.embody .embody_c{
            display: inline-block;
            margin-right:10px;
        }
        .embody_t{
            font-size: 12px;
            color:#999;
        }
        .embody_c{
            font-size: 12px;
        }
        .embody_c img,.embody_c em{
            display: inline-block;
            vertical-align: middle;               
        }
         .embody_c img{               
            width:30px;
            height:30px;
        }
        .embody_c em{
            margin: 0 20px 0 10px;
            color:#333;
            font-style: normal;
        }
</style>
<script type="text/javascript">
    $(function () {
        try
        {
            var lib = eval("("+$("#lib").attr("value")+")");
            var html = "";
            if (lib.err == 0) {
                $.each(lib.data, function (i) {
                    var obj = lib.data[i];
                    //html += '<img src="' + obj.logo + '"/>' + obj.name + "&nbsp;&nbsp;";
                    html += ' <a href="' + obj.url + '" target="_blank">';
                    html += ' <img src="' + obj.logo + '">';
                    html += ' <em><b>' + obj.name + '</b></em>';
                    html += ' </a>';
                });
                if (html != "") {
                    setTimeout(function () {
                        $("#lib").html(html);                      
                        $("#embody").show();
                    }, 100);
                }
            }      
        } catch (err)
        { }
        
    });
</script>
  <div class="category clearfix">
    <div class="category_l">
       <img src="http://static.blog.csdn.net/images/category_icon.jpg">
        <span>分类:</span>
    </div>
    <div class="category_r">
                <label onclick="GetCategoryArticles('1414064','linminqin','top','6697303');">
                    <span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_fenlei']);">Apache工具<em>(2)</em></span>
                  <img class="arrow-down" src="http://static.blog.csdn.net/images/arrow_triangle _down.jpg" style="display:inline;">
                  <img class="arrow-up" src="http://static.blog.csdn.net/images/arrow_triangle_up.jpg" style="display:none;">
                    <div class="subItem">
                        <div class="subItem_t"><a href="http://blog.csdn.net/linminqin/article/category/1414064" target="_blank">作者同类文章</a><i class="J_close">X</i></div>
                        <ul class="subItem_l" id="top_1414064">                            
                        </ul>
                    </div>
                </label>                    
    </div>
</div>
<script type="text/javascript" src="http://static.blog.csdn.net/scripts/category.js"></script>  
    <div class="bog_copyright">         
        <p class="copyright_p">版权声明:本文为博主原创文章,未经博主允许不得转载。</p>
    </div>

populate(bean,map) 将Map中的值设入bean中

  1. BeanUtils.populate(bean, request.getParameterMap());  

PropertyUtils.describe() 方法将返回bean中每个可读的属性都添加到Map中去.如果值为设置,将返回默认值,在上面的例子中假如Book类中还有个Integer型的page属性,代表书籍页数.在没设置的情况下,将返回null.如果page属性为int型,则将返回0

摘自:http://www.blogjava.NET/hexuzhong/archive/2005/11/30/21925.html

  1. Person author = new Person();  
  2. author.setName("Timothy M. O'Brien");  
  3.       
  4. Book book = new Book();  
  5. book.setName("Jakarta Commons Cookbook");  
  6. book.setAuthor(author);  
  7.   
  8. // 取得book中的所有可读属性,返回到map中  
  9. Map bookMap = PropertyUtils.describe(book);  
  10. // Book类中包含一个Author类型的属性  
  11. // 取bookMap中的author bean,并将其所有可读属性返回到authorMap中  
  12. Map authorMap = PropertyUtils.describe(bookMap.get("author"));  
  13.   
  14. // 输出  
  15. // Book Name: Jakarta Commons Cookbook  
  16. // Author Name: Timothy M. O'Brien  
  17. System.out.println("Book Name: " + bookMap.get("name"));  
  18. System.out.println("Author Name: " + authorMap.get("name"));  
    <div id="digg" articleid="6697303">
        <dl id="btnDigg" class="digg digg_disable" onclick="btndigga();">
           
             <dt>顶</dt>
            <dd>1</dd>
        </dl>
       
          
        <dl id="btnBury" class="digg digg_disable" onclick="btnburya();">
          
              <dt>踩</dt>
            <dd>0</dd>               
        </dl>
        
    </div>
 <div class="tracking-ad" data-mod="popu_222"><a href="javascript:void(0);" target="_blank">&nbsp;</a>   </div>
<div class="tracking-ad" data-mod="popu_223"> <a href="javascript:void(0);" target="_blank">&nbsp;</a></div>
<script type="text/javascript">
            function btndigga() {
                $(".tracking-ad[data-mod='popu_222'] a").click();
            }
            function btnburya() {
                $(".tracking-ad[data-mod='popu_223'] a").click();
            }
        </script>
<div style="clear:both; height:10px;"></div>


    <div class="similar_article" style="">
            <h4>我的同类文章</h4>
            <div class="similar_c" style="margin:20px 0px 0px 0px">
                <div class="similar_c_t">
                            <label class="similar_cur">
                                <span style="cursor:pointer" onclick="GetCategoryArticles('1414064','linminqin','foot','6697303');">Apache工具<em>(2)</em></span>
                            </label>
                </div>
               
                <div class="similar_wrap tracking-ad" data-mod="popu_141" style="max-height:195px;">
                    <a href="http://blog.csdn.net" style="display:none" target="_blank">http://blog.csdn.net</a>
                    <ul class="similar_list fl"><li><em>•</em><a href="http://blog.csdn.net/linminqin/article/details/18798781" id="foot_aritcle_18798781undefined74989474812581" target="_blank" title="org.apache.commons.beanutils.ConversionException: No value specified for 'Date'">org.apache.commons.beanutils.ConversionException: No value specified for 'Date'</a><span>2014-01-26</span><label><i>阅读</i><b>10677</b></label></li> </ul>

                    <ul class="similar_list fr"><li><em>•</em><a href="http://blog.csdn.net/linminqin/article/details/7929863" id="foot_aritcle_7929863undefined2344384397348549" target="_blank" title="BeanUtils.copyProperties 如果Integer 或Long 为null 默认赋值0">BeanUtils.copyProperties 如果Integer 或Long 为null 默认赋值0</a><span>2012-08-31</span><label><i>阅读</i><b>3995</b></label></li> </ul>
                </div>
            </div>
        </div>    
<script type="text/javascript">
    $(function () {
        GetCategoryArticles('1414064', 'linminqin','foot','6697303');
    });
</script>
<div>
        <div class="J_adv" data-view="true" data-mod="ad_popu_205" data-mtp="43" data-order="114" data-con="ad_content_1900" style="width: 728px; height: 90px;"><script src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-8990951720398508" data-ad-slot="8267689356/3776917242" data-adsbygoogle-status="done"><ins id="aswift_0_expand" style="display:inline-table;border:none;height:90px;margin:0;padding:0;position:relative;visibility:visible;width:728px;background-color:transparent"><ins id="aswift_0_anchor" style="display:block;border:none;height:90px;margin:0;padding:0;position:relative;visibility:visible;width:728px;background-color:transparent"><iframe width="728" height="90" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" onload="var i=this.id,s=window.google_iframe_oncopy,H=s&amp;&amp;s.handlers,h=H&amp;&amp;H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&amp;&amp;d&amp;&amp;(!d.body||!d.body.firstChild)){if(h.call){setTimeout(h,0)}else if(h.match){try{h=s.upd(h,i)}catch(e){}w.location.replace(h)}}" id="aswift_0" name="aswift_0" style="left:0;position:absolute;top:0;"></iframe></ins></ins></ins><script>(adsbygoogle=window.adsbygoogle || []).push({});</script></div> 
 </div>

参考知识库

img

.NET知识库

 <dt><span>猜你在找</span></dt>    





<div id="adCollege" style="width: 42%;float: left;"> 
    <script src="http://csdnimg.cn/jobreco/job_reco.js" type="text/javascript"></script> 
    <script type="text/javascript">
        csdn.position.showEdu({
            sourceType: "blog",
            searchType: "detail",
            searchKey: "6697303",
            username: "",
            recordcount: "5",
            containerId: "adCollege" //容器DIV的id。 
        });
    </script> 
<div class="tracking-ad" data-mod="popu_84"><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px; white-space: nowrap;"><a href="http://edu.csdn.net/course/detail/1176" title="Python编程基础视频教程(第三季)" strategy="v4:hot" target="_blank">Python编程基础视频教程(第三季)</a></dd><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px; white-space: nowrap;"><a href="http://edu.csdn.net/course/detail/1182" title="Python编程基础视频教程(第六季)" strategy="v4:hot" target="_blank">Python编程基础视频教程(第六季)</a></dd><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px; white-space: nowrap;"><a href="http://edu.csdn.net/course/detail/299" title="从此不求人:自主研发一套PHP前端开发框架" strategy="v4:hot" target="_blank">从此不求人:自主研发一套PHP前端开发框架</a></dd><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px; white-space: nowrap;"><a href="http://edu.csdn.net/course/detail/1153" title="Swift视频教程(第五季)" strategy="v4:hot" target="_blank">Swift视频教程(第五季)</a></dd><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px; white-space: nowrap;"><a href="http://edu.csdn.net/course/detail/925" title="Swift视频教程" strategy="v4:hot" target="_blank">Swift视频教程</a></dd></div></div>  


 <div id="res" data-mod="popu_36" class="tracking-ad" style="width: 42%; float: left; margin-right: 30px; display: block;"><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px;"><a href="http://blog.csdn.net/u010087830/article/details/12647883" title="面试总结" strategy="SearchAlgorithm" target="_blank">面试总结</a></dd><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px;"><a href="http://blog.csdn.net/hepanlaurence/article/details/51479430" title="webmagic采集CSDN的Java_WebDevelop页面" strategy="SearchAlgorithm" target="_blank">webmagic采集CSDN的Java_WebDevelop页面</a></dd><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px;"><a href="http://blog.csdn.net/u014403008/article/details/44623779" title="JAVA面试总结" strategy="SearchAlgorithm" target="_blank">JAVA面试总结</a></dd><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px;"><a href="http://blog.csdn.net/permike/article/details/44906463" title="java相关问题" strategy="SearchAlgorithm" target="_blank">java相关问题</a></dd><dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px;"><a href="http://blog.csdn.net/languobeibei/article/details/53542038" title="android网络编程" strategy="SearchAlgorithm" target="_blank">android网络编程</a></dd></div>
<div id="ad_cen">        
<!-- 广告位开始 -->
<div class="J_adv" data-view="true" data-mod="ad_popu_72" data-mtp="61" data-order="114" data-con="ad_content_1937"><script id="popuLayer_js_q" src="http://ads.csdn.net/js/popuLayer.js" defer="" type="text/javascript"></script><div id="location_parent_google"></div><script src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><div id="layerd_google" style="position: fixed; bottom: 0px; right: 0px; line-height: 0px; z-index: 1000; width: 302px; height: 275px; display: none;"><div class="J_close layer_close" style="display:;background-color:#efefef;padding:0px;color:#333;font:12px/24px Helvetica,Tahoma,Arial,sans-serif;text-align:right;">关闭</div><ins class="adsbygoogle" style="display: inline-block; width: 300px; height: 250px;" data-ad-client="ca-pub-8990951720398508" data-ad-slot="8267689356/2658895482" data-adsbygoogle-status="done"><ins id="aswift_2_expand" style="display:inline-table;border:none;height:250px;margin:0;padding:0;position:relative;visibility:visible;width:300px;background-color:transparent"><ins id="aswift_2_anchor" style="display:block;border:none;height:250px;margin:0;padding:0;position:relative;visibility:visible;width:300px;background-color:transparent"><iframe width="300" height="250" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" onload="var i=this.id,s=window.google_iframe_oncopy,H=s&amp;&amp;s.handlers,h=H&amp;&amp;H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&amp;&amp;d&amp;&amp;(!d.body||!d.body.firstChild)){if(h.call){setTimeout(h,0)}else if(h.match){try{h=s.upd(h,i)}catch(e){}w.location.replace(h)}}" id="aswift_2" name="aswift_2" style="left:0;position:absolute;top:0;"></iframe></ins></ins></ins></div><script>(adsbygoogle=window.adsbygoogle || []).push({});</script><script>  document.getElementById('popuLayer_js_q').onload=function(){      var styObjd=styObj={width:'302px',height:'275px'};window.CSDN.Layer.PopuLayer('#layerd_google',{storageName:'layerd',styleObj:styObjd,total:50,expoire:1000*60});  }</script></div>
<!-- 广告位结束 -->
查看评论

  暂无评论

* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
<div id="ad_bot">
</div>
    <a id="quick-reply" class="btn btn-top q-reply" title="快速回复" style="display:none;">
        <img src="http://static.blog.csdn.net/images/blog-icon-reply.png" alt="快速回复">
    </a>    
<a id="d-top-a" class="btn btn-top backtop" style="display: none;" title="返回顶部" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_huidaodingbu'])">         
     <img src="http://static.blog.csdn.net/images/top.png" alt="TOP">
</a>

                    <div class="clear">
                    </div>
                </div>
posted @ 2017-02-03 10:22  jobs-lgy  阅读(532)  评论(0编辑  收藏  举报