简搭云科技有限公司 简搭云科技有限公司
首页 (opens new window)
  • 可视化表单
  • 流程平台
  • 可视化大屏
  • 在线DB接口
  • 可视化表单
  • 优秀大屏设计
  • 3D样例
  • 视屏教学
  • 可视化表单系统 (opens new window)
  • 可视化大屏系统 (opens new window)
  • 可视化表单系统
  • 可视化大屏
  • 联系我们
  • 可视化表单系统 (opens new window)
  • 可视化大屏系统 (opens new window)

长沙市简搭云科技有限公司

长沙市简搭云科技有限公司
首页 (opens new window)
  • 可视化表单
  • 流程平台
  • 可视化大屏
  • 在线DB接口
  • 可视化表单
  • 优秀大屏设计
  • 3D样例
  • 视屏教学
  • 可视化表单系统 (opens new window)
  • 可视化大屏系统 (opens new window)
  • 可视化表单系统
  • 可视化大屏
  • 联系我们
  • 可视化表单系统 (opens new window)
  • 可视化大屏系统 (opens new window)
  • 可视化表单

  • 流程平台

  • 可视化大屏

  • 动态DB接口

    • 01.简介
    • 02.参数变量标签说明
      • 参数变量标签说明
        • Sql参数
        • #{} 注入参数
        • ${} 拼接参数
        • 动态SQL参数
        • url参数注入
        • head参数注入
        • 环境变量参数注入
        • 查询集成若依数据权限配置
        • 复杂JSON提交时获取参数例子
        • 关键字
        • where
        • if
        • sql 执行sql语句块
        • for
    • 03.界面操作说明
    • 04.接口类型说明
  • 操作手册
  • 动态DB接口
简搭云软件
2023-10-15
国家能源集团
成都智慧城市
优必联智能装备
河北启派科技
深圳市量信科技
杭州市奥哲软件
绍兴瑞楠
麓谷云
南京优玛软件

02.参数变量标签说明

# 参数变量标签说明

# Sql参数

# #{} 注入参数

作用和mybatis一致,都是将#{}区域替换为占位符?

 select * from sys_user where id = #{id}
1

运行时生成的SQL为:select * from sys_user where id = ?。

参数id值会被注入为123。

此方法可以避免sql注入。

# ${} 拼接参数

作用和mybatis一致,都是将${}区域替换为对应的字符串

 select * from sys_user where id = ${id}
1

运行时生成的SQL为:select * from sys_user where id = 123

# 动态SQL参数

通过if标签来实现动态拼接SQL,如果条件成立则拼接后部分内容SQL中,与mybatis是一致的

select * from sys_user <where> <if test="id != null and id != ''"> id=#{id}</if>
// 当id有值时,生成SQL:select * from sys_user where id = ?`
// 当id无值时,生成SQL:select * from sys_user
1
2
3

# url参数注入

select * from sys_user where id = #{$query.id}
// 如请求url地址:http://localhost:8083/api/flow/oa/comm/apiComm/test.getUser?id=44  那生成的SQL为:select * from sys_user where id='44'
1
2

# head参数注入

select * from sys_user where id = #{$header.id}
// 如请求url地址:http://localhost:8083/api/flow/oa/comm/apiComm/test.getUser header中有id为55的变量  那生成的SQL为:select * from sys_user where id='55'
1
2

# 环境变量参数注入

select * from sys_user where id = #{$user.id}
// 通过当前登录用户id 获取当前用户信息。
// $user.id 当前登录用户id,#{$user.userName} 当前登录用户名 #{$user.realaname} 当前登录用户真实名称#{$user.deptcode}当前用户部门编码 #{$user.deptname}当前用户部门名称 #{$user.organcode}当前用户机构编码 #{$user.organname}当前用户机构名称 #{$user.deptid}当前用户部门id #{$user.organid}当前用户机构ID #{$user.password}当前用户的密码 #{$user.phone}当前用户的手机号码 #{$user.avatar}当前用户形象图  $newid 每次赋值都会产生一个新的雪花ID ${$tableNewId} 表单保存时的
1
2
3

# 查询集成若依数据权限配置

select * from sys_user where <if test="$dataScope!=null and $dataScope!=''">and ${$dataScope}</if>
// 加上了${$dataScope} 对应接口会根据登录用户只显示对应若依系统的授权的数据。
1
2

# 复杂JSON提交时获取参数例子

Post Body参数示例1:

{
  id:"1",
  num:22,
  item:{
    name:'测试账号',
    id:'2',
    num:44
  }
}
1
2
3
4
5
6
7
8
9
select * from sys_user where <if test="item.id!=null and item.id!=''">and  id = #{item.id}</if>
// 输出sql为:select * from sys_user where and  id =? 参数值为'2'
select * from sys_user where <if test="item.id!=null and item.id!=''">and  id = #{item.id+id}</if>
// 输出sql为:select * from sys_user where and  id =? 参数值为'12'
select * from sys_user where    id = #{item.num+num} 
// 输出sql为:select * from sys_user where and  id =? 参数值为66
1
2
3
4
5
6

也支持#{A属性+B属性},#{A属性*B属性},#{A属性/B属性},#{A属性-B属性},#{A属性==''?B属性:A属性} 最基础的运算与三元表达式的支持。

接口 Post Body参数示例2:

{
  id:"1",
  num:11,
  name:'测试账号1',
  item:[{
    name:'测试账号2',
    id:'2',
    num:22
  },{
    name:'测试账号3',
    id:'3',
    num:33
  },
  {
    name:'测试账号4',
    id:'4',
    num:44,
    child:[{ name:'测试账号5',
    id:'5',
    num:55,},{ name:'测试账号6',
    id:'6',
    num:66,},]
  },]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

读取item数组对象值

select * from sys_user <where> <if test="item!=null and item.size()>0">and  id = #{item[0].id}</if></where>
// 输出sql为:select * from sys_user where and  id =? 参数值为'2'
select * from sys_user <where> <if test="item!=null and item.size()>2">and  id = #{item[1].id}</if></where>
// 输出sql为:select * from sys_user where and  id =? 参数值为'3'
select * from sys_user <where> <if test="item!=null and item.size()>3">and  id = #{item[2].id}</if></where>
// 输出sql为:select * from sys_user where and  id =? 参数值为'4'
1
2
3
4
5
6

循环数组item对象执行

<for forname="item">
<sql> insert into sys_user(id,user_name) value(#{item[$index0].id},#{item[$index0].name})</sql> 
</if>
//循环item,依次输出sql: insert into sys_user(id,user_name) value(?,?) 参数分别是'2','测试账号2'
//insert into sys_user(id,user_name) value(?,?) 参数分别是'3','测试账号3'
//insert into sys_user(id,user_name) value(?,?) 参数分别是'4','测试账号4'
1
2
3
4
5
6

循环数组item.child对象执行

<for forname="item.child">
<sql> insert into sys_user(id,user_name) value(#{item[$index0].id},#{item[$index0].name})</sql> 
</if>
//循环item,依次输出sql: insert into sys_user(id,user_name) value(?,?) 参数分别是'5','测试账号5'
//insert into sys_user(id,user_name) value(?,?) 参数分别是'6','测试账号6'
1
2
3
4
5

# 关键字

关键字名称
where
if
sql
for

# where

where 跟mybatis的where用法相同,当where标签中有值,就输出where


select * from sys_user <where> <if test="id!=null and id!=''">and  id = #{id}</if></where>
///当post body参数为{id:'22'}时,输出参数为select * from sys_user where id=? 参数值为'22'
///当post body参数为{id:null}时,输出参数为select * from sys_user  
1
2
3
4

# if

if 跟mybatis的if用法相同,当if test条件成立,就输出if标签内容

select * from sys_user <where> <if test="id!=null and id!=''">and  id = #{id}</if></where>
///当post body参数为{id:'22'}时,输出参数为select * from sys_user where id=? 参数值为'22'
///当post body参数为{id:null}时,输出参数为select * from sys_user  
1
2
3

# sql 执行sql语句块

属性 作用
test 条件判断
param 查询结果放入内存中

经典示例

<sql param="$totalcount"> select count(*) rowcount from form_a2aq where fid=#{id} </sql>
<sql test="$totalcount!=null and $totalcount[0].rowcount>0">
update sys_user set user_name=#{username} where fid=#{id}
</sql>
<sql test="$totalcount==null and $totalcount[0].rowcount==0">
insert into sys_user(fid,user_name) values(#{id},#{username})
</sql>
///<sql param="$totalcount"> select count(*) rowcount from form_a2aq where fid=#{id} </sql> 执行查询sql 并将查询的结果值 赋值到$totalcount属性中
///<sql test="$totalcount!=null and $totalcount[0].rowcount>0">update sys_user set user_name=#{username} where fid=#{id}</sql> test 判断查询结果 是否大于0 如果大于0 就执行修改操作 执行sql update sys_user set user_name=#{username} where fid=#{id}
///<sql test="$totalcount==null and $totalcount[0].rowcount==0">insert into sys_user(fid,user_name) values(#{id},#{username})</sql> test 判断查询结果 等于null或者等于0时 执行插入操作   执行sql insert into sys_user(fid,user_name) values(#{id},#{username})
1
2
3
4
5
6
7
8
9
10

# for

for是动态SQL的另一个常见使用场景是对集合进行遍历 循环数组 执行多条sql

<for forname="item">
<sql> insert into sys_user(id,user_name) value(#{item[$index0].id},#{item[$index0].name})</sql>
</for>
///forname 是循环的属性路径
1
2
3
4

嵌套循环

<for forname="item">
<sql> insert into sys_user(id,user_name) value(#{item[$index0].id},#{item[$index0].name})</sql>
<for forname="item[$index0].child">
<sql> insert into sys_user(id,user_name) value(#{item[$index0].child[$index1].id},#{item[$index0].child[$index1].name})</sql>
</for>
</for>
///嵌套循环 $index变量从0开始 每嵌套一次 增加1  如循环<for forname="item[$index0].child"> 它的索引为$index1
1
2
3
4
5
6
7
上次更新: 2024/02/19, 23:02:23
01.简介
03.界面操作说明

← 01.简介 03.界面操作说明→

简搭云软件 | Copyright © 2021-2025 长沙市简搭云科技有限公司
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×