通过jasperreport打印整个HashMap [英] Print whole HashMap by jasperreport

查看:40
本文介绍了通过jasperreport打印整个HashMap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过jasperreport打印整个地图

I need to print whole map by jasperreport

示例:

Column1 Column2

key1        val1

key2        val2

key2        val2

应该选择什么数据源?

报告内容应包含哪些内容?

What should containts report source?

PS:我不想直接获得像$ P {key11}这样的值

PS: I don't want to get values directly like $P{key11}

推荐答案

我会尝试这样的事情

Map<String,Object> map = new HashMap<String,Object>();
//your map values....
Set<Entry<String,Object>> set = map.entrySet();
JRBeanCollectionDataSource bds = new JRBeanCollectionDataSource(set);

在碧玉报告中,您的字段将是

in the jasper report your fields will be

<field name="key" class="java.lang.String"/>
<field name="value" class="java.lang.Object"/>

注意:如何使用Map.Entry bean getKey()getValue()创建数据源

Note: How I'm using the Map.Entry bean getKey() and getValue() to created my datasource

如果您只想实现Comparator并使用Collections,则不会对值进行排序.

The values will not be sorted if you like to sort them just implement a Comparator and use Collections.

    List<Entry<String, Object>> list = new ArrayList<Entry<String, Object>>();
    list.addAll(set);
    Collections.sort(list, new Comparator<Entry<String, Object>>() {
        @Override
        public int compare(Entry<String, Object> o1, Entry<String, Object> o2) {
            // TODO Implement you sorting
            return 0;
        }
    });
    JRBeanCollectionDataSource bdsSorted = new JRBeanCollectionDataSource(list);

这篇关于通过jasperreport打印整个HashMap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆