当前位置: 首页 > 知识库问答 >
问题:

JasperReports与Maven和Eclipse示例

华峰
2023-03-14
  1. JasperReport站点似乎没有任何关于Maven的教程
  2. Maven2JasperReports插件在执行Eclipse插件时出现以下错误,但生命周期配置不包括这些错误:org.codehaus.mojo:jasperReports-maven-plugin:1.0-beta-2:compile-reports
  3. 其他站点上的大多数示例都是使用Ant和Jasper的

共有1个答案

奚晟
2023-03-14

这是一个获取数据的小报告。

这是你的控制器

@RequestMapping(value ="/BMIbyage",method = RequestMethod.GET)
public ModelAndView BMIbyage(ModelAndView modelAndView, ModelMap model, Map<String, Object> map,HttpServletRequest request,
        @RequestParam("syear") int syear,@RequestParam("eyear") int eyear,HttpSession session){
    String childid = (String) session.getAttribute("childid");

    List<AdmissionSummery> asum = new ArrayList<AdmissionSummery>();

     List<PatientDetails> patientdetail = patientService.listpatientbmi();

    for(int i=syear;i<=eyear;i++){
         asum.add(new AdmissionSummery());
        int no=0;
        for(int j=0;j<patientdetail.size();j++){


            int dob = Integer.parseInt(patientdetail.get(j).getDateofbirth().substring(0, 4));

            float bmi = patientService.listPatient(patientdetail.get(j).getChildid()).get(0).getBmi();


            if(dob ==i && (bmi<18.5)){
                no=no+1;

                asum.get(asum.size()-1).setNooftime(no);

            }
            System.out.println("no"+no);
            System.out.println("j"+j);
            asum.get(asum.size()-1).setDuration(syear+" "+"-"+" "+eyear);
            asum.get(asum.size()-1).setYear(i);


            System.out.println("BMI"+bmi);

        }



        System.out.println("i"+i);
    }

      JRDataSource datasource = new JRBeanCollectionDataSource(asum);   

        model.addAttribute("datasourcebmireportA", datasource);

        model.addAttribute("format", "pdf");

        modelAndView = new ModelAndView("pdfReportViewaddsummeryA", model);



    return modelAndView;


}

下面是您的设计器xml

<title>
    <band height="122" splitType="Stretch">
        <rectangle>
            <reportElement x="4" y="100" width="197" height="20"/>
        </rectangle>
        <textField>
            <reportElement x="193" y="71" width="166" height="19"/>
            <textElement>
                <font size="14" isBold="true"/>
            </textElement>
            <textFieldExpression class="java.lang.String"><![CDATA[$F{duration}]]></textFieldExpression>
        </textField>
        <staticText>
            <reportElement x="5" y="9" width="526" height="37"/>
            <textElement textAlignment="Center">
                <font size="14" isBold="true"/>
            </textElement>
            <text><![CDATA[Paediatric Professional Unit -Ward 11
       Teaching Hospital Jaffna]]></text>
        </staticText>
        <line>
            <reportElement x="5" y="92" width="550" height="1" forecolor="#CCCCCC"/>
            <graphicElement>
                <pen lineWidth="2.0"/>
            </graphicElement>
        </line>
        <staticText>
            <reportElement x="5" y="102" width="51" height="20"/>
            <textElement textAlignment="Center" verticalAlignment="Middle">
                <font size="12" isBold="true"/>
            </textElement>
            <text><![CDATA[Year]]></text>
        </staticText>
        <staticText>
            <reportElement x="5" y="53" width="526" height="46"/>
            <textElement>
                <font size="14" isBold="true"/>
            </textElement>
            <text><![CDATA[
        BMI value < 18.5kg/m2 -]]></text>
        </staticText>
        <staticText>
            <reportElement x="59" y="102" width="142" height="20"/>
            <textElement textAlignment="Center" verticalAlignment="Middle">
                <font size="12" isBold="true"/>
            </textElement>
            <text><![CDATA[Number of Admission]]></text>
        </staticText>
        <line>
            <reportElement x="56" y="100" width="1" height="20"/>
        </line>
    </band>
</title>
<pageHeader>
    <band splitType="Stretch"/>
</pageHeader>
<columnHeader>
    <band splitType="Stretch"/>
</columnHeader>
<detail>
    <band height="21">
        <rectangle>
            <reportElement x="4" y="0" width="197" height="20">
                <printWhenExpression><![CDATA[$F{year}!=0]]></printWhenExpression>
            </reportElement>
        </rectangle>
        <textField>
            <reportElement x="56" y="2" width="145" height="17"/>
            <textElement textAlignment="Center" verticalAlignment="Middle"/>
            <textFieldExpression class="java.lang.Integer"><![CDATA[$F{nooftime}]]>           </textFieldExpression>
        </textField>
        <textField>
            <reportElement x="5" y="1" width="51" height="20">
                <printWhenExpression><![CDATA[$F{year}!=0]]></printWhenExpression>
             </reportElement>
            <textElement textAlignment="Center" verticalAlignment="Middle"/>
            <textFieldExpression class="java.lang.Integer"><![CDATA[$F{year}]]>      </textFieldExpression>
        </textField>
        <line>
            <reportElement x="55" y="1" width="1" height="19">
                <printWhenExpression><![CDATA[$F{year}!=0]]></printWhenExpression>
            </reportElement>
        </line>
    </band>
</detail>
<summary>
<tr>
    <td  ><a href="#"><div class="box">
        <form action="BMIbyage">
        <table width="754">
        <tr>
        <td width="190">
        <font color="black">BMI value < 18.5kg/m2</font></td>

        <td width="124"></td>

        <td width="82">
    <select name="syear"> 
    <option value="Pleaseselect">----</option>
                <%for(int j=1980;j<=2030;j++)
                {
                    %>
                    <option value="<%=j%>"><%=j%></option>
                    <%
                    }
                    %>
    </select>
    </td>
    <td width="20"> to </td>
  <td width="178">
    <select name="eyear"> 
    <option value="Pleaseselect">----</option>
                <%for(int j=1980;j<=2030;j++)
                {
                    %>
                    <option value="<%=j%>"><%=j%></option>
                    <%
                    }
                    %>
    </select>
    </td>
    <td width="108"><input type="submit" value="Generate"></td>
    </tr>
    </table>
        </form>

    </div></a></td>
    </tr>
<bean id="pdfReportViewaddsummeryA"
class="org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView"
 p:url="/WEB-INF/Reports/BMIReport.jasper"
 p:reportDataKey="datasourcebmireportA"
 />
<!--    report
     -->
    <dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>3.7.6</version>
    <type>jar</type>
    <scope>compile</scope>
    <exclusions>
        <exclusion>
            <artifactId>commons-collections</artifactId>
            <groupId>commons-collections</groupId>
        </exclusion>
        <exclusion>
            <artifactId>commons-beanutils</artifactId>
            <groupId>commons-beanutils</groupId>
        </exclusion>
        <exclusion>
            <artifactId>commons-digester</artifactId>
            <groupId>commons-digester</groupId>
        </exclusion>
        <exclusion>
            <artifactId>commons-logging</artifactId>
            <groupId>commons-logging</groupId>
        </exclusion>
    </exclusions>
</dependency>
 类似资料:
  • 我将询问关于Eclipse/NetBeans和Maven的问题,但首先让我陈述一下我的更高目标,我只是猜测Eclipse/NetBeans和Maven将是一个很好的组合。 我是一个经验丰富的程序员,也是几种语言的计算机科学导师,但我是第一次学习Java。我在帮一个学生跟我一起学。 我最习惯Emacs,并且我很好地将JDEE模式与Maven协同工作。 我的学生发现Emacs笨拙,想用别的东西。他到目

  • 问题内容: 有谁知道使用maven和eclipse使用GWT的新2.0版本创建项目的好指南?我遇到了很多问题,无法让他们一起好好玩。 对于它的价值,我可以使用maven eclipse插件创建一个gwt项目,该插件可以正常工作,但是将其移植到maven则行不通(因此这方面的指南会很棒)。 同样,我可以使用Maven插件(gwt-maven- plugin),但是当我将其导入eclipse(导入->

  • 我试图设置新的Web项目使用最新的Maven,GWT和Eclipse。我试图生成它与可用的原型从GWT Maven插件与命令: mvn原型:generate-DarchetypeGroupId=org。科德豪斯。mojo-DarchetypeArtifactId=gwt maven插件-DarchetypeVersion=2.4。0-DarchetypeRepository=repo1。专家组织机

  • 我试图使用e(fx)clipse与java8和eclipse Luna在我的mac(优胜美地)。 在终端中:java-version给了我 java版本“1.8.0_25”java(TM)SE运行时环境(构建1.8.0_25-b17)java热点(TM)64位服务器虚拟机(构建25.25-b02,混合模式) 在我的eclipse.ini,我把: -vm/Library/Internet插件/Jav