代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。