如何在JasperReports中按需更改变量值

Saq*_*eed 5 variables parameters jasper-reports ireport

我正在使用iReport.情况如下:

我有一些名为的参数branchID, spType.

我创建了一个名为的变量branchName (string) ,默认为null.

我需要做的是,要改变/编辑变量的值branchName取决于值branchIDspType

如何使用If Else 使用JasperReports执行此操作.它是变量属性的东西branchName吗?任何帮助/建议将受到高度赞赏.

Kah*_*wan 7

Jasper报告中的表达式脚本语言是你的朋友!

我可以从您的查询中了解到,您希望根据两个参数的值计算变量的值.简而言之,你想做的事情如下: -

简单的if-else

If (branchId == 1 && spType == "abc") 
     branchName = "Xyz1";
 else 
     branchName = "Xyz2";
Run Code Online (Sandbox Code Playgroud)

在Jasper脚本语言中,上面的表达式可以写成:

($P{branchId}==1 && 
 $P{spType} != null &&
 $P{spType}.equals("abc"))?"Xyz1":"Xyz2"
Run Code Online (Sandbox Code Playgroud)

嵌套的If-else

If (branchId == 1 && spType == "abc") 
    branchName = "Xyz1";
 else if (branchId = 2 && spType == "def")
    branchName = "Xyz2"; 
 else 
    branchName = "Xyz3";
Run Code Online (Sandbox Code Playgroud)

贾斯珀表达:

( $P{branchId} ==1 &&
  $P{spType} !=null && 
  $P{spType}.equals("abc") ) ? "Xyz1" :
    (($P{branchId} == 2 &&
      $P{spType} != null &&
      $P{spType}.equals("def")) ? "Xyz2" : "Xyz3");
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请查看本教程:http: //www.tutorialspoint.com/jasper_reports/jasper_report_expression.htm

这里有一个类似的stackoverflow问题: 在JasperReports中进行比较if else

对于核心概念,Page no.本pdf中的10个:http: //jasperreports.sourceforge.net/JasperReports-Ultimate-Guide-3.pdf