请求包含参数的报告 [英] Request report with parameters

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

问题描述

我想用带有多个参数的 JasperReports 创建一个报告,当用户传递所有参数时报告是正确生成的,但是当一个参数丢失时没有生成任何内容我使用此请求

I want to create a report with JasperReports with multiple parameters, the report is generated correctly when the user passes all the parameters but nothing is generated when one parameter is missed i use this request

  SELECT
     t.*,
     u."name" AS username,
     c."name" AS componentName,
     s."designation" AS statusName,
     pr."name" AS priorityName,
     p."name" AS projectName
FROM
     "component" c INNER JOIN "ticket" t ON c."id" = t."component_id"
     INNER JOIN "personne" u ON t."personne_id" = u."id"
     INNER JOIN "status" s ON t."status_id" = s."id"
     INNER JOIN "priority" pr ON t."priority_id" = pr."id"
     INNER JOIN "project" p ON c."project_id" = p."id"
WHERE
     pr.name = $P{priority}
and u.login = $P{userLogin}
and s.designation = $P{status}
and t.creation_date between $P{start} and $P{end}
and c.name = $P{componenet}

请你帮我生成报告错过了一个参数?

Please can you help me to generate the report even where there is one parameter missed?

推荐答案

在生成报告之前,您可以控制java类中的where子句。


1.在java中你可以检查参数是否为null,然后进行小验证,例如

You can control the where clause in java class before generate the report.

1.In java u can check whether the parameter is null or not, then do small validation such as

StringBuffer sb = new StringBuffer();
if(StringUtils.isNotEmpty(priority)){
        sb.append(" AND pr.name = "+priority);
    }

2.do为 u的所有其他条件。 login,s.designation


3.之后你可以传递 reportParam.put(sqlQuery,sb.toString());

4.在ireport中只需更改您的查询

4.the in ireport simply change your query

WHERE
pr.name = $P{priority}
and u.login = $P{userLogin}
and s.designation = $P{status}
and t.creation_date between $P{start} and $P{end}
and c.name = $P{componenet}

WHERE 1=1 $P!{sqlQuery}

现在你不用担心 null ,因为它会忽略java类中的条件。

now you dont need to worry about the null, since it will ignore the condition in java class.

这篇关于请求包含参数的报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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