mirror of
				https://github.com/beego/bee.git
				synced 2025-11-04 04:13:26 +00:00 
			
		
		
		
	add post and put json invalid fomart filter
This commit is contained in:
		
							
								
								
									
										10
									
								
								g_appcode.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								g_appcode.go
									
									
									
									
									
								
							@@ -1172,13 +1172,16 @@ func (c *{{ctrlName}}Controller) URLMapping() {
 | 
			
		||||
// @router / [post]
 | 
			
		||||
func (c *{{ctrlName}}Controller) Post() {
 | 
			
		||||
	var v models.{{ctrlName}}
 | 
			
		||||
	json.Unmarshal(c.Ctx.Input.RequestBody, &v)
 | 
			
		||||
	if err := json.Unmarshal(c.Ctx.Input.RequestBody, &v); err == nil {
 | 
			
		||||
		if _, err := models.Add{{ctrlName}}(&v); err == nil {
 | 
			
		||||
			c.Ctx.Output.SetStatus(201)
 | 
			
		||||
			c.Data["json"] = v
 | 
			
		||||
		} else {
 | 
			
		||||
			c.Data["json"] = err.Error()
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		c.Data["json"] = err.Error()
 | 
			
		||||
	}
 | 
			
		||||
	c.ServeJson()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -1273,12 +1276,15 @@ func (c *{{ctrlName}}Controller) Put() {
 | 
			
		||||
	idStr := c.Ctx.Input.Params[":id"]
 | 
			
		||||
	id, _ := strconv.Atoi(idStr)
 | 
			
		||||
	v := models.{{ctrlName}}{Id: id}
 | 
			
		||||
	json.Unmarshal(c.Ctx.Input.RequestBody, &v)
 | 
			
		||||
	if err := json.Unmarshal(c.Ctx.Input.RequestBody, &v); err == nil {
 | 
			
		||||
		if err := models.Update{{ctrlName}}ById(&v); err == nil {
 | 
			
		||||
			c.Data["json"] = "OK"
 | 
			
		||||
		} else {
 | 
			
		||||
			c.Data["json"] = err.Error()
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		c.Data["json"] = err.Error()
 | 
			
		||||
	}
 | 
			
		||||
	c.ServeJson()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user