在jasper报告中编写方法? [英] Writing methods in jasper report?

查看:93
本文介绍了在jasper报告中编写方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个jasper报告。在那里我想编写一个接受整数并进行一些处理并返回一个字符串的方法。我不知道如何在jasper report中编写方法。是否可以编写?可以任何一个帮助我

I am creating a jasper report.In that I want to write one method which takes integer and does some process and returns a string.I dont know how to write methods in jasper report.Is it possible to write?Can any one help me in this

我正在使用iReport3.6.0。

I am using iReport3.6.0.

示例代码:

 <textField>
  <reportElement x="400" y="10" width="80" height="15"/>
  <textElement textAlignment="Left" verticalAlignment="Middle"/>
  <textFieldExpression     class="java.lang.String">
               <![CDATA[$F{intValue}]]>
  </textFieldExpression>
 </textField>

在上面的代码中,$ F {intValue}返回integer.I想将它传递给一个方法并且返回类型的方法想要成为字符串。

In the above code "$F{intValue}" returns integer.I want pass that to one method and that methods return type wants to be string.

谢谢

推荐答案

使用静态方法编写辅助Java类将接收整数参数并返回所需结果:

Write a helper Java class with a static method that will receive the integer argument and return desired outcome:

package com.yourname.reports.util;

public class JrUtils {
  public static String intFormatter(int arg) {
    return "Beautified int: " + arg;
  }
}

将此类添加到用于编译jasperreports模板的类路径中并为运行时。在iReport中,右键单击报表检查器视图中的报表标题,然后选择属性。向下滚动到'Imports'并添加您的班级:

Add this class to the classpath used for compiling jasperreports template and for the runtime. In the iReport right click on report's title in 'Report Inspector' view and choose 'Properties'. Scroll down to 'Imports' and add your class:

com.yourname.reports.util.JrUtils

将导入Java类添加到报表中并使用以下方法从字段调用静态方法:

Add import Java class to your report and invoke the static method from the field using:

<![CDATA["Transformed int: " + JrUtils.intFormatter($F{intValue}) ]>

这篇关于在jasper报告中编写方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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