Skip to content

Commit 7622388

Browse files
author
yanglibing
committed
解决dml mysql 语法错误
1 parent 9a5e620 commit 7622388

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

src/com/yanglb/utilitys/codegen/core/translator/BaseDdlTranslator.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ public class BaseDdlTranslator extends BaseTranslator<List<DdlModel>> {
3131
// 外键关系列表
3232
protected List<ForeignModel> foreignKeyList = new ArrayList<ForeignModel>();
3333

34-
// 列引号字符,如:SQL Server为[], MySQL为`等
35-
protected String sqlColumnStart = "\"";
36-
// 列引号字符,如:SQL Server为[], MySQL为`等
37-
protected String sqlColumnEnd = "\"";
38-
3934
@Override
4035
protected void onBeforeTranslate() throws CodeGenException {
4136
super.onBeforeTranslate();

src/com/yanglb/utilitys/codegen/core/translator/BaseTranslator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public class BaseTranslator<T> implements ITranslator<T> {
3232
protected HashMap<String, String> settingMap;
3333
protected ParamaModel paramaModel;
3434

35+
// 列引号字符,如:SQL Server为[], MySQL为`等
36+
protected String sqlColumnStart = "\"";
37+
protected String sqlColumnEnd = "\"";
38+
3539
protected BaseTranslator() {
3640
this.writableModel = new WritableModel();
3741
}

src/com/yanglb/utilitys/codegen/core/translator/impl/DmlTranslatorImpl.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ protected void onBeforeTranslate() throws CodeGenException {
4444
fileName = fileName.substring(0, index);
4545
}
4646
this.writableModel.setFileName(fileName);
47+
48+
Map<String, String> options = this.paramaModel.getOptions();
49+
if (options.containsKey("type")) {
50+
String type = options.get("type");
51+
if (type.equals("mysql")) {
52+
this.sqlColumnEnd = this.sqlColumnStart = "`";
53+
}
54+
}
4755
}
4856

4957
@Override
@@ -142,7 +150,7 @@ private String genColumns(String[] data) {
142150
if(!StringUtility.isNullOrEmpty(columns)) {
143151
columns += ", ";
144152
}
145-
columns += String.format("\"%s\"", col);
153+
columns += String.format("%s%s%s", this.sqlColumnStart, col, this.sqlColumnEnd);
146154
}
147155
return columns;
148156
}

src/com/yanglb/utilitys/codegen/shell/CodeGenShell.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public boolean invoke(String[] args) {
8181
* 显示帮助信息
8282
*/
8383
private void showHelp() {
84-
System.out.println("代码生成器 v2.0 使用说明");
84+
System.out.println("代码生成器 v2.0.1 使用说明");
8585
System.out.println("Copyright 2015-2016 yanglb.com All Rights Reserved.");
8686
System.out.println();
8787
System.out.println("用法:");

template/DML模板.xlsx

-484 KB
Binary file not shown.

0 commit comments

Comments
 (0)