mirror of
https://github.com/beego/bee.git
synced 2024-11-23 11:50:55 +00:00
Complete controller modification
This commit is contained in:
parent
e6815f495e
commit
48817da755
@ -146,6 +146,7 @@ var controllerModelTpl = `package {{packageName}}
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"{{pkgPath}}/models"
|
"{{pkgPath}}/models"
|
||||||
|
"{{pkgPath}}/structures"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -174,7 +175,7 @@ func (c *{{controllerName}}Controller) URLMapping() {
|
|||||||
// @Failure 403 body is empty
|
// @Failure 403 body is empty
|
||||||
// @router / [post]
|
// @router / [post]
|
||||||
func (c *{{controllerName}}Controller) Post() {
|
func (c *{{controllerName}}Controller) Post() {
|
||||||
var v models.{{controllerName}}
|
var v structures.{{controllerName}}
|
||||||
json.Unmarshal(c.Ctx.Input.RequestBody, &v)
|
json.Unmarshal(c.Ctx.Input.RequestBody, &v)
|
||||||
if _, err := models.Add{{controllerName}}(&v); err == nil {
|
if _, err := models.Add{{controllerName}}(&v); err == nil {
|
||||||
c.Ctx.Output.SetStatus(201)
|
c.Ctx.Output.SetStatus(201)
|
||||||
@ -275,7 +276,7 @@ func (c *{{controllerName}}Controller) GetAll() {
|
|||||||
func (c *{{controllerName}}Controller) Put() {
|
func (c *{{controllerName}}Controller) Put() {
|
||||||
idStr := c.Ctx.Input.Param(":id")
|
idStr := c.Ctx.Input.Param(":id")
|
||||||
id, _ := strconv.ParseInt(idStr, 0, 64)
|
id, _ := strconv.ParseInt(idStr, 0, 64)
|
||||||
v := models.{{controllerName}}{Id: id}
|
v := structures.{{controllerName}}{Id: id}
|
||||||
json.Unmarshal(c.Ctx.Input.RequestBody, &v)
|
json.Unmarshal(c.Ctx.Input.RequestBody, &v)
|
||||||
if err := models.Update{{controllerName}}ById(&v); err == nil {
|
if err := models.Update{{controllerName}}ById(&v); err == nil {
|
||||||
c.Data["json"] = "OK"
|
c.Data["json"] = "OK"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013 Dylan LYU (mingzong.lyu@gmail.com)
|
// Copyright 2016 Dylan LYU (mingzong.lyu@gmail.com)
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
||||||
// not use this file except in compliance with the License. You may obtain
|
// not use this file except in compliance with the License. You may obtain
|
||||||
|
Loading…
Reference in New Issue
Block a user