NutzCN Logo
问答 有没有办法将 Json化的SqlExpressionGroup 转回 SqlExpressionGroup 对象?
发布于 544天前 作者 ericleung 642 次浏览 复制 上一个帖子 下一个帖子
标签:

正在做一个项目,条件由前端组装,传到后台后转为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
}
3 回复

Json.toJson/fromJson 试试?

SqlExpressionGroup 没有public 构造函数啊, 难产了

Object aa = Json.fromJson(jsonStr);

        SqlExpressionGroup gg = Mapl.maplistToT(aa, SqlExpressionGroup.class);

        System.out.println(Json.toJson(gg));
org.nutz.lang.born.BorningException: Fail to born or cast to 'org.nutz.dao.util.cri.SqlExpression'
 by args: []
 because: No suitable Constructor or Factory Method!!

看来得加一个

添加回复
请先登陆
回到顶部