How can I pass an arbitrary object to jasper report as parameter?

后端 未结 2 757
遇见更好的自我
遇见更好的自我 2020-12-15 00:11

I would like to pass as a parameter to my .jrxml an arbitrary object of my domain, e.g a Person.

InputStream reportFile = MyPage.this.getClass().getResource         


        
相关标签:
2条回答
  • 2020-12-15 00:25

    Yes, it is possible exactly the way you explained. Just make sure you have the correct classpath when compiling the jrxml and be careful with the case - either lowercase (person) or uppercase (PERSON) in all places.

    0 讨论(0)
  • 2020-12-15 00:34

    Yes, you can pass any Java object, but you should make sure to import that object in the JRXML.

    Inside the jasperReport tag. You can use the tag import, like:

     <jasperReport...>
          <import value="org.justfortest.Person">
    

    However, you can use JRBeanCollectionDataSource and populate the report with a list of your object, without needing to store arbitrary objects in the params map.

    Check this tutorial for more info on Jasper Reports Bean Collection Data Source

    0 讨论(0)
提交回复
热议问题