Skip to content

Commit

Permalink
add print decode TempleteDecoder.go control print
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Mar 15, 2020
1 parent ac25d93 commit 4b251e3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
13 changes: 10 additions & 3 deletions GoMybatisTempleteDecoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var equalOperator = []string{"/", "+", "-", "*", "**", "|", "^", "&", "%", "<",
TODO sqlTemplete解析器,目前直接操作*etree.Element实现,后期应该改成操作xml,换取更好的维护性
*/
type GoMybatisTempleteDecoder struct {
print bool
}

type LogicDeleteData struct {
Expand All @@ -33,6 +34,10 @@ type VersionData struct {
LangType string
}

func (it *GoMybatisTempleteDecoder) SetPrintElement(print bool) {
it.print = print
}

func (it *GoMybatisTempleteDecoder) DecodeTree(tree map[string]etree.Token, beanType reflect.Type) error {
if tree == nil {
return utils.NewError("GoMybatisTempleteDecoder", "decode data map[string]*MapperXml cant be nil!")
Expand Down Expand Up @@ -72,9 +77,11 @@ func (it *GoMybatisTempleteDecoder) DecodeTree(tree map[string]etree.Token, bean
if beanType != nil {
beanName = beanType.String()
}
var s = "================DecoderTemplete " + beanName + "." + v.SelectAttrValue("id", "") + "============\n"
printElement(v, &s)
println(s)
if it.print {
var s = "================DecoderTemplete " + beanName + "." + v.SelectAttrValue("id", "") + "============\n"
printElement(v, &s)
println(s)
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion README-ch.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ go env -w GOSUMDB=off
//go.mod加入依赖
require (
github.com/go-sql-driver/mysql v1.5.0
github.com/zhuxiujia/GoMybatis v6.2.0+incompatible
github.com/zhuxiujia/GoMybatis v6.2.1+incompatible
)
```

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ go get github.com/go-sql-driver/mysql
//go.mod加入依赖
require (
github.com/go-sql-driver/mysql v1.5.0
github.com/zhuxiujia/GoMybatis v6.2.0+incompatible
github.com/zhuxiujia/GoMybatis v6.2.1+incompatible
)
```

Expand Down
1 change: 1 addition & 0 deletions TempleteDecoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import (
)

type TempleteDecoder interface {
SetPrintElement(print bool)
DecodeTree(tree map[string]etree.Token, beanType reflect.Type) error
}
3 changes: 3 additions & 0 deletions example/Example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func init() {
}
engine = GoMybatis.GoMybatisEngine{}.New()

//设置打印自动生成的xml 到控制台方便调试,false禁用
engine.TempleteDecoder().SetPrintElement(true)

//mysql链接格式为 用户名:密码@(数据库链接地址:端口)/数据库名称 例如root:123456@(***.mysql.rds.aliyuncs.com:3306)/test
_, err := engine.Open("mysql", MysqlUri) //此处请按格式填写你的mysql链接,这里用*号代替
if err != nil {
Expand Down

0 comments on commit 4b251e3

Please sign in to comment.