REST 接口接收内容为空时,默认为 {}

This commit is contained in:
刘祥超
2022-09-24 18:35:29 +08:00
parent 4947f13416
commit 934b10a254

View File

@@ -170,6 +170,11 @@ func (this *RestServer) handle(writer http.ResponseWriter, req *http.Request) {
return return
} }
// 如果为空,表示传的数据为空
if len(body) == 0 {
body = []byte("{}")
}
// 请求数据 // 请求数据
var reqValue = reflect.New(method.Type().In(1).Elem()).Interface() var reqValue = reflect.New(method.Type().In(1).Elem()).Interface()
err = json.Unmarshal(body, reqValue) err = json.Unmarshal(body, reqValue)