急求java任务解决方案。。。做了好几天,头疼啊。本人小白。

{
"tables": [
{
"name_en": "atable",
"name_ch": "表中文名",
"column": [
{
"name_en": "columnA1",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
},
{
"name_en": "columnA2",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
}
],
"select_columns": [
{
"name_en": "sa1",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
},
{
"name_en": "sa2",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
}
],
"order_columns": [
{
"name_en": "oa1",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
},
{
"name_en": "oa2",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
}
],
"where_columns": [
{
"name_en": "wa1",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
},
{
"name_en": "wa2",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
}
]
},
{
"name_en": "btable",
"name_ch": "表中文名",
"column": [
{
"name_en": "columnB1",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
},
{
"name_en": "columnB2",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
}
],
"select_columns": [
{
"name_en": "sb1",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
},
{
"name_en": "sb2",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
}
],
"order_columns": [
{
"name_en": "ob1",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
},
{
"name_en": "ob2",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
}
],
"where_columns": [
{
"name_en": "wb1",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
},
{
"name_en": "wb2",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
}
]
},
{
"name_en": "ctable",
"name_ch": "表中文名",
"column": [
{
"name_en": "columnC1",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
},
{
"name_en": "columnC2",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
}
],
"select_columns": [
{
"name_en": "sc1",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
},
{
"name_en": "sc2",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
}
],
"order_columns": [
{
"name_en": "oc1",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
},
{
"name_en": "oc2",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
}
],
"where_columns": [
{
"name_en": "wc1",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
},
{
"name_en": "wc2",
"name_ch": "中文名",
"colType": "列类型",
"keyType": "PK/FK"
}
]
}
],
"relations": [
{
"tableA": "atable",
"columnA": "columnA1",
"tableB": "btable",
"columnB": "columnB1",
"type": "leftjoin"
},
{
"tableA": "btable",
"columnA": "columnB2",
"tableB": "ctable",
"columnB": "columnC2",
"type": "innerjoin"
}
]
}

这是一串已知的JSON,有tables和relations两个对象。table里面有三张表,每张表里的coulum指该表包含的所有字段,select__columns指要查询的所有字段,ord er_column指要排序的所有字段,where_column指条件所有字段。relations里面是连接查询。

要求:输入一串json,返回一句连接查询的SQL语句。(json里面表数据会根据输入而不同)。

我做了很多方案:
1、创建实体类的话,就不能解决输入不确定参数数量的问题,比如我不知道几张表,每张表要select多少字段;
2、如果一股脑将所输入的json全部存入一个或者多个list集合里面,那我就不能解决最后拼接成一句sql语句的问题;

关键点就是,固定表数量或者select数量,我可以很好的解决,但是,不确定数量的话,我就很难输出并拼接成一句sql语句。

求大神。。。刚实习,头疼,四天了。。没做出来。

4个回答

类似输出这种sql语句。

图片说明

类似输出这种sql语句。

如果是我,我会创建七个实体类,六个来封装"table", "column" 之类的。最后一个用来接收json,看条件,属性应该都是List类型。

楼上的说法很有道理,不过七个实体类要放在一个tableClass下

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问