func bindStruct(params *revel.Params, name string, typ reflect.Type) reflect.Value { result := reflect.New(typ).Elem() fieldValues := make(map[string]reflect.Value) for key, _ := range params.Values { suffix := strings.TrimSpace(key) fieldName := nextKey(suffix) if _, ok := fieldValues[fieldName]; !ok { fieldValue := result.FieldByName(fieldName) if !fieldValue.IsValid() { continue } if !fieldValue.CanSet() { continue } boundVal := revel.Bind(params, fieldName, fieldValue.Type()) fieldValue.Set(boundVal) fieldValues[fieldName] = boundVal } } return result }
// fmt.Println("xx: " + fieldName) fieldValue := result.FieldByName(fieldName) // fmt.Println(fieldValue) if !fieldValue.IsValid() { continue } if !fieldValue.CanSet() { continue } var boundVal reflect.Value // 没有name前缀 if noPrefix { // life // fmt.Println("<<") // fmt.Println(strings.Title(key[:fieldLen])); boundVal = revel.Bind(params, key[:fieldLen], fieldValue.Type()) } else { // fmt.Println("final") // fmt.Println(key[:len(name)+1+fieldLen]) // files[0][HasBody if nameIsSlice { fieldLen += 1 } boundVal = revel.Bind(params, key[:len(name)+1+fieldLen], fieldValue.Type()) } fieldValue.Set(boundVal) fieldValues[fieldName] = boundVal } } return result }, Unbind: func(output map[string]string, name string, iface interface{}) {