Skip to content

Commit

Permalink
修改默认参数逻辑,默认参数为arg0,arg1....
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Jun 21, 2019
1 parent 911788a commit b5b4088
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions GoMybatis.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ func buildSql(proxyArg ProxyArg, nodes []ast.Node, sqlBuilder SqlBuilder) (Sessi
paramMap[lowerKey] = argInterface
paramMap[upperKey] = argInterface
} else {
paramMap[DefaultOneArg] = argInterface
//未命名参数,为arg加参数位置,例如 arg0,arg1,arg2....
paramMap[DefaultOneArg+strconv.Itoa(argIndex)] = argInterface
}
}
if customLen == 1 && customIndex != -1 {
Expand Down Expand Up @@ -502,7 +503,7 @@ func scanStructArgFields(v reflect.Value, tag *TagArg) map[string]interface{} {
structArg[typeValue.Name] = obj
}
}
if tag != nil && parameters[tag.Name]==nil{
if tag != nil && parameters[tag.Name] == nil {
parameters[tag.Name] = structArg
}
return parameters
Expand Down
4 changes: 2 additions & 2 deletions GoMybatisConst.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package GoMybatis

const DefaultOneArg = `[default]`

//默认参数前缀,例如arg0 arg1 arg2 ....
const DefaultOneArg = `arg`
3 changes: 2 additions & 1 deletion GoMybatisTempleteDecoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/zhuxiujia/GoMybatis/lib/github.com/beevik/etree"
"github.com/zhuxiujia/GoMybatis/utils"
"reflect"
"strconv"
"strings"
)

Expand Down Expand Up @@ -623,7 +624,7 @@ func (it *GoMybatisTempleteDecoder) DecodeCollectionName(method *reflect.StructF
var mapperParams = method.Tag.Get("mapperParams")
var args = strings.Split(mapperParams, ",")
if mapperParams == "" || args == nil || len(args) == 0 || (len(args) == 1 && args[0] == "") {
collection = DefaultOneArg
collection = DefaultOneArg + strconv.Itoa(i)
} else {
collection = args[i]
}
Expand Down

0 comments on commit b5b4088

Please sign in to comment.