正在做一个项目,条件由前端组装,传到后台后转为SqlExpressionGroup 对象,这样就可以直接操作了。
有没有办法呢?
原始的SQL
WHERE (name='小白' OR name='小黑' AND (id NOT IN (1,2) OR age<10 AND (age BETWEEN 1 AND 100 AND LOWER(name) LIKE LOWER('%哈哈%'))) AND length BETWEEN '1' AND '10')
JSON化是:
{
"exps": [{
"op": "=",
"value": "小白",
"not": false,
"name": "name",
"top": true
}, {
"str": "OR",
"top": true
}, {
"op": "=",
"value": "小黑",
"not": false,
"name": "name",
"top": true
}, {
"str": "AND",
"top": true
}, {
"exps": [{
"ids": [1, 2],
"not": true,
"name": "id",
"top": true
}, {
"str": "OR",
"top": true
}, {
"op": "<",
"value": 10,
"not": false,
"name": "age",
"top": true
}, {
"str": "AND",
"top": true
}, {
"exps": [{
"min": 1,
"max": 100,
"not": false,
"name": "age",
"top": true
}, {
"str": "AND",
"top": true
}, {
"value": "哈哈",
"ignoreCase": true,
"left": "%",
"right": "%",
"not": false,
"name": "name",
"top": true
}],
"not": false,
"top": false
}],
"not": false,
"top": false
}, {
"str": "AND",
"top": true
}, {
"min": "1",
"max": "10",
"not": false,
"name": "length",
"top": true
}],
"not": false,
"top": true
}