相信看过第二章《uReport2报表工具的基础使用及注意事项》的读者们应该对uReport2的基础操作会有所了解的,本章就开始讲述一下,如何在uReport2的SQL语句中添加查询参数并且访问报表页面。
(一)添加查询参数
(二)不确定传参方式
${ "select * from sys_role where 1=1"+ (param("id")!=null && param("id")!="" ? " and id = \'"+param("id")+"\'":" ") #多个参数 直接添加在下方即可 #(param("name")!=null && param("name")!="" ? " and name = \'"+param("name")+"\'":" ") }
注:此处编写时需要注意空格的使用,比如and前面不能省略空格,否则Sql语句将解析为:
select * from sys_role where 1=1and id = '1'
(三)如何传参及访问报表页面
那我们要怎么去测试传入参数和访问报表页面呢?还记得我们打开预览的报表文件时默认访问的链接是http://localhost:8080/ureport/preview?_u=p,因此我们需要修改当前链接的参数,如:http://localhost:8080/ureport/preview?_u=file:roleSelect1.ureport.xml,这里的file对应的就是我们所保存的报表文件,它是以xml文件的形式保存到webapp/WEB-INF/ureportfiles下的。
最后我们只需要在这个链接中添加参数即可,如下所示:
#不传入参数 http://localhost:8080/ureport/preview?_u=file:roleSelect1.ureport.xml #传入参数 http://localhost:8080/ureport/preview?_u=file:roleSelect1.ureport.xml&id=1
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/202315.html原文链接:https://javaforall.net
