SQL标签
- 使用SQL标签可写sql语句,并执行查询,把查询结果显示在页面上。
- 只有当具体的业务标签不能满足要求时才使用SQL标签。
- 使用本标签可扩展出其它业务标签(写sql)
|
类型
|
标签
名
|
作用
|
参数
|
返回值
|
完成
|
||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| SQL标签 | sql.queryList(){} |
执行动态SQL,查多行 |
|
List<Map<String,Object>> | 已完成 | ||||||||||||||||||||||||
| SQL标签 | sql.queryPage(){} | 执行动态SQL,分页查询 |
|
Page | 已完成 | ||||||||||||||||||||||||
| SQL标签 | sql.queryOne(){} | 执行动态SQL,查一行 |
|
Map<String,Object> | 已完成 | ||||||||||||||||||||||||
| SQL函数 | sql.param(); |
|
已完成 | ||||||||||||||||||||||||||
| SQL函数 | sql.include(); |
用于加载一个sql文件, 或加载sql文件的一部分,支持局部渲染技术 |
|
已完成 | |||||||||||||||||||||||||
| 内置函数 |
global("变量名") |
取出sql.queryXxx标签的查询结果 |
|
已完成 |
使用示例一
sql.queryPage标签测试
在模板中动态拼接SQL
<%
var id=57;
var name="张三";
%>
<%sql.queryPage({outVar:"product_page5",debug:true}){%>
select * from product_kkk where 1=1
<%if(id!=null){ %>and id=${sql.param(id)}<%}%>
<%if(name!=null){ %>and name=${sql.param(name)}<%}%>
order by id desc
<%}%>
<%for(item in global("product_page5").list){%>
<span>你的ID是:${item.id},姓名是:${item.name}</span>
<%}%>
使用示例二
sql.queryPage标签测试
在独立文件中动态拼接SQL,并演示了一个sql文件中存放多条Sql。
<%
var id=57;
var name="张三";
%>
<%sql.queryPage({outVar:"product_page5",debug:true}){%>
<%sql.include("/demo/sql/a.sql#select_product_1",{id:102,name:"李891"});%>
<%}%>
<%for(item in global("product_page5").list){%>
<span>你的ID是:${item.id},姓名是:${item.name}</span>
<%}%>
独立的/demo/sql/a.sql文件
<%#ajax select_product_1:{%>
select * from product_spu1 where 1=1
<%if(id!=null){ %>and id=${sql.param(id)}<%}%>
<%if(name!=null){ %>and name=${sql.param(name)}<%}%>
order by id desc
<%}%>
<%#ajax select_product_2:{%>
select * from product_spu2 where 1=1
<%if(id!=null){ %>and id=${sql.param(id)}<%}%>
<%if(name!=null){ %>and name=${sql.param(name)}<%}%>
order by id desc
<%}%>