zoukankan      html  css  js  c++  java
  • jasperreports ireport使用sql语句中有in时动态赋值

     <parameter name="
    a_id" class="java.util.List"/>
     <queryString language="SQL">
      <![CDATA[select * from Apoplexy where  $X{IN, apoplexy_id, 
    a_id}]]>

     </queryString>

    import net.sf.jasperreports.engine.JRExporter;
    import net.sf.jasperreports.engine.JRExporterParameter;
    import net.sf.jasperreports.engine.JRPrintPage;
    import net.sf.jasperreports.engine.JasperFillManager;
    import net.sf.jasperreports.engine.JasperPrint;
    import net.sf.jasperreports.engine.JasperReport;
    import net.sf.jasperreports.engine.export.JRHtmlExporter;
    import net.sf.jasperreports.engine.export.JRHtmlExporterParameter;
    import net.sf.jasperreports.engine.export.JRPdfExporter;
    import net.sf.jasperreports.engine.export.JRXlsExporter;
    import net.sf.jasperreports.engine.export.JRXlsExporterParameter;

    import net.sf.jasperreports.engine.util.JRLoader; 

    public void report() throws ServletException, IOException {
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpServletResponse response = ServletActionContext.getResponse();
    String jasper = "report/ApoplexyReport.jasper"; // 你的jasper文件地址
    String filename = "中疯病患者详细信息报表"; // 
    // 各种参数设置好
    List<Integer> collection = new ArrayList<Integer>();
    collection.add(14);
    collection.add(15);
    collection.add(16);
    collection.add(17);
    collection.add(18);
    collection.add(19);
    collection.add(20);
    collection.add(21);
    collection.add(22);
    collection.add(23);
    collection.add(24);
    collection.add(25);
    Map map = new HashMap();
    map.put("a_id", collection);
    try {
    // 读取jasper
    JasperReport jr = (JasperReport) JRLoader
    .loadObjectFromLocation(jasper);
    Connection conn = DBConnection.getConnection();
    // 填充数据
    JasperPrint jp = JasperFillManager.fillReport(jr, map, conn);
    // 判断是否正常
    List<JRPrintPage> pages = jp.getPages();
    // ReportType.export(response, jp, ReportType.EXCEL, filename);
    ReportType.export(response, jp, ReportType.HTML, filename);
    } catch (Exception ex) {
    System.out.println(ex.toString());
    }
    }
    public void export(HttpServletResponse response, JasperPrint jp, int type,
    String filename) throws Exception {
    JRExporter exporter = null;
    int HTML = 1;
    int EXCEL = 2;
    final int PDF = 3;
    if (type == HTML) {
    exporter = new JRHtmlExporter();
    exporter.setParameter(
    JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, false);
    exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML,
    "");
    // exporter.setParameter(JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,
    // Boolean.TRUE);
    } else if (type == EXCEL) {
    exporter = new JRXlsExporter();
    response.setContentType("application/vnd.ms-excel");
    response.addHeader("Content-Disposition", new String(
    ("attachment; filename=" + filename + ".xls")
    .getBytes("GBK"), "ISO-8859-1"));
    exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,
    Boolean.FALSE);
    // exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,
    // Boolean.TRUE);
    } else if (type == PDF) {
    exporter = new JRPdfExporter();
    response.setContentType("application/pdf");
    response.addHeader("Content-Disposition", new String(
    ("attachment; filename=" + filename + ".pdf")
    .getBytes("GBK"), "ISO-8859-1"));
    } else {
    return;
    }
    exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "GBK");
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, response
    .getOutputStream());
    exporter.exportReport();


  • 相关阅读:
    python base64加密文本内容(1)
    python 翻译爬虫
    json为txt文本加密
    python json
    repr()函数
    linux 基本命令
    测试管理工具--禅道
    测试基础理论
    测试用例--场景法
    测试用例--测试大纲(提纲)法
  • 原文地址:https://www.cnblogs.com/fanstatic/p/2125072.html
Copyright © 2011-2022 走看看