@@ -13,9 +13,11 @@ import (
1313 "github.com/xfali/gobatis-cmd/common"
1414 "github.com/xfali/gobatis-cmd/io"
1515 "strings"
16+ "time"
1617)
1718
1819func genXml (config Config , tableName string , model []common.ModelInfo ) {
20+ common .SelectKeyWordFormatter (config .Driver )
1921 if config .MapperFile == "xml" {
2022 xmlDir := config .Path + "xml/"
2123 if ! io .IsPathExists (xmlDir ) {
@@ -27,7 +29,7 @@ func genXml(config Config, tableName string, model []common.ModelInfo) {
2729
2830 builder := strings.Builder {}
2931 buildMapper (& builder , config , tableName , model ,
30- formatXmlColumns , formatBackQuoteXml , formatBackQuoteXml )
32+ formatXmlColumns , common . KwFormatter , common . KwFormatter )
3133 io .Write (xmlFile , []byte (builder .String ()))
3234 }
3335 } else if config .MapperFile == "go" {
@@ -64,6 +66,12 @@ type fomatter func(string) string
6466func buildMapper (builder * strings.Builder , config Config , tableName string , model []common.ModelInfo ,
6567 columnsFunc func (string , []common.ModelInfo ) string , tableFunc , columnFunc fomatter ) {
6668 modelName := common .TableName2ModelName (tableName )
69+ builder .WriteString (fmt .Sprintf ("<!--This file was generated by xfali/gobatis-cmd at -->" ))
70+ builder .WriteString (common .Newline ())
71+ builder .WriteString (fmt .Sprintf ("<!--%s-->" , time .Now ().String ()))
72+ builder .WriteString (common .Newline ())
73+ builder .WriteString (common .Newline ())
74+
6775 builder .WriteString (fmt .Sprintf ("<mapper namespace=\" %s.%s\" >" , config .PackageName , modelName ))
6876 builder .WriteString (common .Newline ())
6977
@@ -254,38 +262,29 @@ func getIfStr(ctype, name string) string {
254262 return strings .Replace (sqlType2IfFormatMap [ctype ], "%s" , fmt .Sprintf ("{%s}" , name ), - 1 )
255263}
256264
257- func formatGoColumns (tableName string , model []common.ModelInfo ) string {
258- columns := "` + \" "
265+ func formatXmlColumns (tableName string , model []common.ModelInfo ) string {
266+ columns := ""
259267 for i := range model {
260- columns += formatColumnName ( tableName , model [i ].ColumnName )
268+ columns += common . KwFormatter ( model [i ].ColumnName )
261269 if i < len (model )- 1 {
262270 columns += ","
263271 }
264272 }
265- columns += "\" + `"
266273 return columns
267274}
268275
269- func formatXmlColumns (tableName string , model []common.ModelInfo ) string {
270- columns := ""
271- tableName = fmt .Sprintf ("`%s`" , tableName )
276+ func formatGoColumns (tableName string , model []common.ModelInfo ) string {
277+ columns := "` + \" "
272278 for i := range model {
273- columns += formatColumnName ( tableName , model [i ].ColumnName )
279+ columns += common . KwFormatter ( model [i ].ColumnName )
274280 if i < len (model )- 1 {
275281 columns += ","
276282 }
277283 }
284+ columns += "\" + `"
278285 return columns
279286}
280287
281288func formatBackQuoteGo (src string ) string {
282289 return "` + \" `" + src + "`\" + `"
283290}
284-
285- func formatBackQuoteXml (src string ) string {
286- return fmt .Sprintf ("`%s`" , src )
287- }
288-
289- func formatColumnName (tableName , columnName string ) string {
290- return fmt .Sprintf ("`%s`" , columnName )
291- }
0 commit comments