当前位置:网站首页>连表查询 select 生成
连表查询 select 生成
2022-07-01 00:32:00 【呜呜艾伦】
连表查询 select 生成
结果
select
plan.*,
time_slot.*,
program.*
from plan, plan_time_slot,
time_slot, time_slot_program,
program
where plan.id = plan_time_slot.plan_id
and plan_time_slot. time_slot_id = time_slot.id
and time_slot.id = time_slot_program.time_slot_id
and time_slot_program. program_id = program.id ;
package com.gm.wj.util;
import com.gm.wj.entity.Notice;
import lombok.Data;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@Data
public class CodeGen {
// public static void main(String[] args) {
List<String> tableNames=new ArrayList<>();
List<String> tableNames= Arrays.asList("plan","time_slot","program");
int frontIdx=0;
int linkIdx=1;
int endIdx=2;
String whereCode=" where ";
for (int i = 0; i < tableNames.size(); i++) {
String frontTable = tableNames.get(frontIdx);
String linkTable = tableNames.get(linkIdx);
String backTable = tableNames.get(endIdx);
String linkTableName=frontTable+"_"+backTable;
whereCode+="#frontTable#.id = #linkTableName#.#frontTable#_id ";
whereCode+="#linkTableName#. #endTable#_id = #endTable#.id ";
}
// List<String> tableNames= Arrays.asList("plan","time_slot","program");
// String whereCode = makeWhereCode(tableNames);
// String selectCode = makeSelectCode(tableNames);
// String fromCode = makeFromCode(tableNames);
// System.out.println(selectCode+fromCode+whereCode);
// }
static String makeFromCode( List<String> tableNames){
// List<String> tableNames= Arrays.asList("plan","time_slot","program");
int frontIdx=0;
// int linkIdx=1;
int backIdx=1;
// int endIdx=2;
// String whereCode=" where ";
// 0 1 2
StringBuilder whereCode= new StringBuilder(" from ");
String firstTable = tableNames.get(0);
whereCode.append(firstTable).append(", ");
for (int i = 0; i < tableNames.size(); i++) {
String frontTable = tableNames.get(frontIdx);
// String linkTable = tableNames.get(backIdx);
String backTable = tableNames.get(backIdx);
// String backTable = tableNames.get(endIdx);
String linkTableName=frontTable+"_"+backTable;
// whereCode.append(" #frontTable#,\n#linkTableName#,\n#backTable#,"
whereCode.append(" #linkTableName#,\n#backTable#,"
.replace("#frontTable#", frontTable)
.replace("#backTable#", backTable)
.replace("#linkTableName#", linkTableName))
;
frontIdx++;
backIdx++;
if(backIdx>=tableNames.size()){
break;
}
}
// whereCode.rela
whereCode = new StringBuilder(whereCode.substring(0, whereCode.length() - 1));
whereCode.append("\n");
// whereCode= whereCode.replaceFirst("and","where");
// System.out.println(whereCode);
return whereCode.toString();
}
static String makeSelectCode( List<String> tableNames){
// List<String> tableNames= Arrays.asList("plan","time_slot","program");
int frontIdx=0;
// int linkIdx=1;
int backIdx=1;
// int endIdx=2;
// String whereCode=" where ";
StringBuilder whereCode= new StringBuilder(" select \n");
String firstTable = tableNames.get(0);
whereCode.append(firstTable+".*").append(",\n ");
List<String>codes=new ArrayList<>();
for (int i = 0; i < tableNames.size(); i++) {
String frontTable = tableNames.get(frontIdx);
// String linkTable = tableNames.get(backIdx);
String backTable = tableNames.get(backIdx);
// String backTable = tableNames.get(endIdx);
String linkTableName=frontTable+"_"+backTable;
// whereCode.append(" #frontTable#.*, \n #backTable#.*,"
codes.add(backTable+".*");
// whereCode.append(" #backTable#.*,"
// .replace("#frontTable#", frontTable)
// .replace("#backTable#", backTable)
// .replace("#linkTableName#", linkTableName))
// ;
frontIdx++;
backIdx++;
if(backIdx>=tableNames.size()){
break;
}
}
// System.out.println(codes);
String tables = String.join(",\n", codes);
whereCode.append(tables);
// whereCode = new StringBuilder(whereCode.substring(0, whereCode.length() - 1));
whereCode.append("\n");
// System.out.println(whereCode);
return whereCode.toString();
}
static String makeWhereCode( List<String> tableNames){
// List<String> tableNames= Arrays.asList("plan","time_slot","program");
int frontIdx=0;
// int linkIdx=1;
int backIdx=1;
// int endIdx=2;
// String whereCode=" where ";
StringBuilder whereCode= new StringBuilder(" ");
for (int i = 0; i < tableNames.size(); i++) {
String frontTable = tableNames.get(frontIdx);
// String linkTable = tableNames.get(backIdx);
String backTable = tableNames.get(backIdx);
// String backTable = tableNames.get(endIdx);
String linkTableName=frontTable+"_"+backTable;
whereCode.append(" \n and #frontTable#.id = #linkTableName#.#frontTable#_id \n and #linkTableName#. #backTable#_id = #backTable#.id "
.replace("#frontTable#", frontTable)
.replace("#backTable#", backTable)
.replace("#linkTableName#", linkTableName))
;
frontIdx++;
backIdx++;
if(backIdx>=tableNames.size()){
break;
}
}
whereCode = new StringBuilder(whereCode.toString().replaceFirst("and", "where"));
// System.out.println(whereCode);
return whereCode.toString();
}
public static void main(String[] args) {
// Notice notice = new Notice();
// String gen = gen(notice);
// System.out.println(gen);
// CodeGen codeGen = new CodeGen();
// codeGen.genAxios(notice);
codeGen.axiosGetCode.so
// System.out.println(codeGen.axiosPostCode);
List<String> tableNames= Arrays.asList("plan","time_slot","program");
// String whereCode = makeWhereCode(tableNames);
// String selectCode = makeSelectCode(tableNames);
// String fromCode = makeFromCode(tableNames);
// System.out.println(selectCode+fromCode+whereCode);
String linkedTableQuery = genLinkedTableQuery(tableNames);
System.out.println(linkedTableQuery);
}
static String genLinkedTableQuery( List<String> tableNames){
// List<String> tableNames= Arrays.asList("plan","time_slot","program");
String whereCode = makeWhereCode(tableNames);
String selectCode = makeSelectCode(tableNames);
String fromCode = makeFromCode(tableNames);
// System.out.println(selectCode+fromCode+whereCode);
return selectCode+fromCode+whereCode+";";
}
String axiosGetCode;
String axiosPostCode;
public void genAxios(Object object) {
String tableName = getTableName(object);
String jsonAllFiled = ObjectToJson.Object2JsonAllFiled(object);
String axiosGetCodeTpl = "axios.get( common.baseURL + \"/#tableName#\").then((resp) => {\n" +
" if (resp && resp.code === 200) {\n" +
" let data=resp.data.data\n" +
" this.#tableName#=data\n"+
" }\n" +
" });";
String axiosPostCodeTpl = "axios.post( common.baseURL + \"/#tableName#\",#dataForm#).then((resp) => {\n" +
" if (resp && resp.code === 200) {\n" +
" let data=resp.data.data\n" +
" this.#tableName#=data\n"+
" }\n" +
" });";
axiosGetCode = axiosGetCodeTpl.replace("#tableName#", tableName);
axiosPostCode = axiosPostCodeTpl.replace("#tableName#", tableName)
.replace("#dataForm#", jsonAllFiled);
}
public static String gen(Object object) {
String tableName = getTableName(object);
String jsonAllFiled = ObjectToJson.Object2JsonAllFiled(object);
String axiosCode = "axios.get( common.baseURL + \"/#tableName#\").then((resp) => {\n" +
" if (resp && resp.code === 200) {\n" +
" let data=resp.data.data" +
" }\n" +
" });";
String axiosPostCode = "axios.post( common.baseURL + \"/#tableName#\",#dataForm#).then((resp) => {\n" +
" if (resp && resp.code === 200) {\n" +
" let data=resp.data.data" +
" }\n" +
" });";
String replace = axiosCode.replace("#tableName#", tableName);
String replace1 = axiosPostCode.replace("#tableName#", tableName)
.replace("#dataForm#", jsonAllFiled);
return replace;
}
// public static <T> String getTableName(T obj) {
// String tableName = obj.getClass().getSimpleName();
// tableName = StringUtils.underscoreNameLower(tableName);
// return tableName;
// }
public static String getTableName(Object obj) {
String tableName = obj.getClass().getSimpleName();
tableName = StringUtils.underscoreNameLower(tableName);
return tableName;
}
}
边栏推荐
- leetcode 474. Ones and zeroes (medium)
- Advanced mathematical modeling
- Makefile notes (Yiwen Institute makefile)
- CentOS installation starts redis
- C WinForm program interface optimization example
- Member management applet actual development 07 page Jump
- New trend of embedded software development: Devops
- The programmer's girlfriend gave me a fatigue driving test
- 2022-06-30: what does the following golang code output? A:0; B:2; C: Running error. package main import “fmt“ func main()
- Using Excel to quickly generate SQL statements
猜你喜欢

Makefile notes (Yiwen Institute makefile)

Design e-commerce seckill system
![[designmode] factory pattern](/img/62/9be808b3e1c2139d564caa307fcd30.png)
[designmode] factory pattern

2022-2028 global ICT test probe industry research and trend analysis report

女朋友说:你要搞懂了MySQL三大日志,我就让你嘿嘿嘿!

Implementation of OSD on Hisilicon platform (1)

Detailed explanation of conv2d -- use in arrays and images

20220215-ctf-misc-buuctf-ningen--binwalk analysis --dd command separation --archpr brute force cracking

2022-2028 global ultra high purity electrolytic iron sheet industry research and trend analysis report

SSM integration process (integration configuration, function module development, interface test)
随机推荐
20220216 misc buuctf another world WinHex, ASCII conversion flag zip file extraction and repair if you give me three days of brightness zip to rar, Morse code waveform conversion mysterious tornado br
Rhai - rust's embedded scripting engine
CentOS 6.3 x64 PHP 5.2.6 扩展安装OpenSSL出错的解决方法
Yboj mesh sequence [Lagrange interpolation]
CTF tool (1) -- archpr -- including installation / use process
Gateway service gateway
Redis - understand the master-slave replication mechanism
网上开华泰证券的股票账户是否安全呢?
2022-2028 global plant peptone industry research and trend analysis report
CSDN常用复杂公式模板记录
C /platform:anycpu32bitpererrored can only be used with /t:exe, /t:winexe and /t:appcontainerexe
"Experience" my understanding of user growth "new users"
Implementation of OSD on Hisilicon platform (1)
What is the fastest way to import data from HDFS to Clickhouse? Spark is imported through JDBC or HDFS
[UML] UML class diagram
Vmware16 installing win11 virtual machine (the most complete step + stepping on the pit)
1009 product of polynomials (25 points) [PTA class A]
Wordpress blog uses volcano engine veimagex for static resource CDN acceleration (free)
[PHP] self developed framework qphp, used by qphp framework
Unit test concept and purpose