File tree Expand file tree Collapse file tree 5 files changed +37
-3
lines changed
src/main/java/com/yanglb/codegen Expand file tree Collapse file tree 5 files changed +37
-3
lines changed Original file line number Diff line number Diff line change 1616package com .yanglb .codegen .core .parser .impl ;
1717
1818import com .yanglb .codegen .core .parser .BaseParser ;
19+ import org .apache .commons .cli .Option ;
20+ import org .apache .commons .cli .Options ;
1921
2022public class DmlParser extends BaseParser {
23+ @ Override
24+ protected Options options () {
25+ Options options = super .options ();
26+
27+ Option target = Option .builder ()
28+ .longOpt ("target" )
29+ .hasArg ()
30+ .desc ("指定生成目标,可选 mysql/mssql/sqlite,默认为mysql" )
31+ .build ();
32+ options .addOption (target );
33+ return options ;
34+ }
35+
2136 @ Override
2237 protected boolean headerHelp () {
2338 System .out .println ("生成初始数据SQL脚本,用于向数据添加初始数据。" );
Original file line number Diff line number Diff line change 1717
1818import java .util .List ;
1919
20- import com .yanglb .codegen .exceptions .CodeGenException ;
21-
2220public class BaseSqlTranslator <T > extends BaseTranslator <List <T >> {
2321 // 列引号字符,如:SQL Server为[], MySQL为`等
2422 protected String sqlColumnStart = "\" " ;
Original file line number Diff line number Diff line change 2828
2929public class DdlSqliteTranslatorImpl extends BaseDdlTranslator {
3030
31+ public DdlSqliteTranslatorImpl () {
32+ this .sqlColumnStart = "\" " ;
33+ this .sqlColumnEnd = "\" " ;
34+ }
35+
3136 @ Override
3237 protected void onBeforeTranslate () throws CodeGenException {
3338 super .onBeforeTranslate ();
Original file line number Diff line number Diff line change @@ -41,6 +41,22 @@ protected void onBeforeTranslate() throws CodeGenException {
4141 fileName = fileName .substring (0 , index );
4242 }
4343 this .writableModel .setFileName (fileName );
44+
45+ String target = parameterModel .getOptions ().getOptionValue ("target" , "mysql" );
46+ switch (target ) {
47+ case "mysql" :
48+ sqlColumnStart = "`" ;
49+ sqlColumnEnd = "`" ;
50+ break ;
51+ case "mssql" :
52+ sqlColumnStart = "[" ;
53+ sqlColumnEnd = "[" ;
54+ break ;
55+ case "sqlite" :
56+ sqlColumnStart = "\" " ;
57+ sqlColumnEnd = "\" " ;
58+ break ;
59+ }
4460 }
4561
4662 @ Override
Original file line number Diff line number Diff line change 1717
1818public class Infos {
1919 public static final String Name = "Code Generator" ;
20- public static final String Version = "4.0.3 " ;
20+ public static final String Version = "4.1.0 " ;
2121 public static final String Copyright = "Copyright 2015-2020 yanglb.com All Rights Reserved." ;
2222 public static final String Author = "me@yanglb.com" ;
2323 public static final String Website = "https://yanglb.com" ;
You can’t perform that action at this time.
0 commit comments