<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Oracle神諭

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      284 隨筆 :: 9 文章 :: 106 評論 :: 0 Trackbacks

    13.7. JasperReports
    JasperReports (http://jasperreports.sourceforge.net) is a powerful, open-source reporting engine that supports the creation of report designs using an easily understood XML file formats. JasperReports is capable of rendering reports output into four different formats: CSV, Excel, HTML and PDF.

    13.7.1. Dependencies (依賴)
    Your application will need to include the latest release of JasperReports, which at the time of writing was 0.6.1. JasperReports itself depends on the following projects:

    BeanShell

    Commons BeanUtils

    Commons Collections

    Commons Digester

    Commons Logging

    iText

    POI

    JasperReports also requires a JAXP compliant(適應的) XML parser.

    13.7.2. Configuration(配置)
    To configure JasperReports views in your ApplicationContext you have to define a ViewResolver to map view names to the appropriate view class depending on which format you want your report rendered in.

    13.7.2.1. Configuring the ViewResolver
    Typically, you will use the ResourceBundleViewResolver to map view names to view classes and files in a properties file

    <bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
        <property name="basename">
            <value>views</value>
        </property>
    </bean>
                     
    Here we've configured an instance of ResourceBundleViewResolver which will look for view mappings in the resource bundle with base name views. The exact contents of this file is described in the next section.

    13.7.2.2. Configuring the Views
    Spring contains five different View implementations for JasperReports four of which corresponds to one of the four output formats supported by JasperReports and one that allows for the format to be determined at runtime:

    JasperReport View Class
    1.JasperReportsView           CSV
    2.JasperReportsHtmlView       HTML
    3.JasperReportsPdfView        PDF
    4.JasperReportsXlsView        EXCEL
    5.JasperReportsMutiFormatView

    Mapping one of these classes to a view name and a report file is simply a matter of adding the appropriate entries into the resource bundle configured in the previous section as shown here:

    simpleReport.class=org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView
    simpleReport.url=/WEB-INF/reports/DataSourceReport.jasper
                 
    Here you can see that the view with name, simpleReport, is mapped to the JasperReportsPdfView class. This will cause the output of this report to be rendered in PDF format. The url property of the view is set to the location of the underlying report file.


    13.7.2.3. About Report Files
    JasperReports has two distinct types of report file: the design file, which has a .jrxml extension, and the compiled report file, which has a .jasper extension. Typically, you use the JasperReports Ant task to compile your .jrxml design file into a .jasper file before deploying it into your application. With Spring you can map either of these files to your report file and Spring will take care of compiling the .jrxml file on the fly for you. You should note that after a .jrxml file is compiled by Spring, the compiled report is cached for the life of the application. To make changes to the file you will need to restart your application.

    JasperReports擁有兩種不同的類型的報表文件:設計文件,它是一個擁有.jrxml 擴展的文件,和編譯好的報表文件。一般,你使用ant任務在你部署到你的程序中之前來編譯你的.jrxml設計報表文件。使用Spring 你可以影射這些文件中的任一到你的報表文件,Spring將會為你在空閑時照顧編譯.jrxml文件。 你應當注意在一個.jrxml文件被編譯之后,這個編譯的報表是被緩存的在你的application生命周期中。如果這些文件修改了,你需要重新啟動的你的程序。

    13.7.2.4. Using JasperReportsMultiFormatView  使用JasperReportsMutiFormatView
    The JasperReportsMultiFormatView allows for report format to be specified at runtime. The actual rendering of the report is delegated to one of the other JasperReports view classes - the JasperReportsMultiFormatView class simply adds a wrapper layer that allows for the exact implementation to be specified at runtime.

    JasperReportsMutilFormatView允許你在運行時期指定報表的格式。報表的實際的表現是為委托到JasperReports 視圖類的中的一個--JasperMutilFormatView類簡單的加了一個包裝層允許在運行時期正確的實現被指定。

    The JasperReportsMultiFormatView class introduces two concepts: the format key and the discriminator key. The JasperReportsMultiFormatView class uses the mapping key to lookup the actual view implementation class and uses the format key to lookup up the mapping key. From a coding perspective you add an entry to your model with the formay key as the key and the mapping key as the value, for example:

     

    public ModelAndView handleSimpleReportMulti(HttpServletRequest request,
    HttpServletResponse response) throws Exception {

      String uri = request.getRequestURI();
      String format = uri.substring(uri.lastIndexOf(".") + 1);

      Map model = getModel();
      model.put("format", format);

      return new ModelAndView("simpleReportMulti", model);
    }
    In this example, the mapping key is determined from the extension of the request URI and is added to the model under the default format key: format. If you wish to use a different format key then you can configure this using the formatKey property of the JasperReportsMultiFormatView class.

    By default the following mapping key mappings are configured in JasperReportsMultiFormatView:
    Table 13.3. JasperReportsMultiFormatView Default Mapping Key Mappings

    Mapping Key View Class
    csv   JasperReportsCsvView
    html  JasperReportsHtmlView
    pdf   JasperReportsPdfView
    xls   JasperReportsXlsView

    So in the example above a request to URI /foo/myReport.pdf would be mapped to the JasperReportsPdfView class. You can override the mapping key to view class mappings using the formatMappings property of JasperReportsMultiFormatView.

    posted on 2005-06-29 10:24 java世界暢談 閱讀(3462) 評論(0)  編輯  收藏 所屬分類: Spring
    主站蜘蛛池模板: 亚洲精品老司机在线观看| 亚洲精品免费观看| 久久免费高清视频| 亚洲精品日韩专区silk| 蜜臀91精品国产免费观看| 国产精品免费大片一区二区| 亚洲黄色免费观看| 永久免费视频v片www| 一区二区三区免费视频网站| 亚洲综合视频在线| 国产成人在线观看免费网站 | a色毛片免费视频| 亚洲国产成人精品无码一区二区 | 久久久青草青青国产亚洲免观| 日韩精品无码一区二区三区免费| 一本色道久久88亚洲综合| 日本免费中文视频| 爱爱帝国亚洲一区二区三区| 亚洲AV福利天堂一区二区三| 国产裸模视频免费区无码| 免费A级毛片无码视频| 免费毛片毛片网址| 亚洲av日韩av综合| 亚洲bt加勒比一区二区| 国产免费拔擦拔擦8x| 在免费jizzjizz在线播| 国产VA免费精品高清在线| 亚洲国产成人久久精品大牛影视| 色噜噜综合亚洲av中文无码| 亚洲精品无码你懂的网站| 大学生高清一级毛片免费| 最近免费mv在线电影| 国产做国产爱免费视频| 黄色大片免费网站| 亚洲中文字幕久久无码| 亚洲黄色免费电影| 日本红怡院亚洲红怡院最新| 亚洲精品和日本精品| 国产精品免费视频一区| 99re热免费精品视频观看| 日本免费人成视频在线观看|