1. Bind
var req = &vo.RegisterRequest{}
ctx.Bind(&req)
It writes a 400 error and sets Content-Type header “text/plain” in the response if input is not valid.
input不合理时,gin出错后会返回一个文本
2. ShouldBind
相比于bind, 出错后可以以json格式返回。可判断错误
if err := ctx.ShouldBind(&req); err != nil {
response.Fail(ctx, "数据验证错误,分类名称必须填", nil)
return
}
3. MustBindWith
MustBindWith最终也是调用了SouldBindWith,并且对ShouldBindWith的结果进行了判断,如果有错误,则以http 400的状态码进行退出。