5 Star 47 Fork 19

aurora-engine / gobatis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
for_silce.go 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
aurora.io 提交于 2022-12-06 16:34 . 更新 gobatis 报名
package gobatis
import (
"fmt"
"reflect"
"strings"
)
type Slice struct {
/*
实现普通切片的数据处理
*/
}
func (s Slice) ForEach(value any, template string, separator string) (string, string, []any, error) {
var v any
var err error
var item, itemSql string
var param []any
items := make([]string, 0)
tempSql := make([]string, 0)
params := make([]any, 0)
valueOf := reflect.ValueOf(value)
for i := 0; i < valueOf.Len(); i++ {
IndexV := valueOf.Index(i)
v = IndexV.Interface()
if IndexV.Kind() == reflect.Slice {
return "", "", nil, fmt.Errorf("'slice' element error")
}
if IndexV.Kind() == reflect.Map {
ctx := v.(map[string]any)
item, itemSql, param, err = AnalysisForTemplate(template, ctx, nil)
if err != nil {
return "", "", nil, err
}
items = append(items, item)
tempSql = append(tempSql, itemSql)
params = append(params, param...)
continue
}
item, itemSql, param, err = AnalysisForTemplate(template, nil, v)
if err != nil {
return "", "", nil, err
}
items = append(items, item)
tempSql = append(tempSql, itemSql)
params = append(params, param...)
}
join := strings.Join(items, separator)
s2 := strings.Join(tempSql, separator)
return join, s2, params, nil
}
Go
1
https://gitee.com/aurora-engine/gobatis.git
git@gitee.com:aurora-engine/gobatis.git
aurora-engine
gobatis
gobatis
master

搜索帮助