Jasper reports JasperReports表达式中的字符串比较

Jasper reports JasperReports表达式中的字符串比较,jasper-reports,Jasper Reports,使用以下方法查询名为income\u source的数据库字段: SELECT * FROM table_name WHERE income_source LIKE "salaried%" 这将检索带有“受薪”前缀的income\u source值。在iReport中,字段的打印时间设置为: $F{income_source}.equals("Salaried")? Boolean.TRUE:Boolean.FALSE 为什么报表输出与SQL输出不同?有几个问题: SQL中的值“sal

使用以下方法查询名为
income\u source
的数据库字段:

SELECT * FROM table_name WHERE income_source LIKE "salaried%"
这将检索带有“受薪”前缀的
income\u source
值。在iReport中,字段的打印时间设置为:

$F{income_source}.equals("Salaried")? Boolean.TRUE:Boolean.FALSE  

为什么报表输出与SQL输出不同?

有几个问题:

  • SQL中的值“salaried%”与表达式中的值“salaried%”不同
  • “salaried%”
    使用
    %
    匹配字母
    d
    后的所有文本
  • 当按下时,打印中有一点冗余
请尝试以下表达式:

$F{income_source}.startsWith( "salaried" )
或:

其中一个应该有效。选中null时,您还需要确保为空。否则,表达式变为:

$F{income_source} == null ? Boolean.FALSE :
  $F{income_source}.trim().toLowerCase().startsWith( "salaried" )
$F{income_source} == null ? Boolean.FALSE :
  $F{income_source}.trim().toLowerCase().startsWith( "salaried" )