当前位置: 首页 > 工具软件 > beego_weixin > 使用案例 >

beego项目04_管理员(增删改查)

邹涵畅
2023-12-01

完整代码

// manager.go
package admin

import (
	"strconv"
	"strings"
	"xiaomi/models"
)

type ManagerController struct {
	BaseController

}

func (c *ManagerController) Get(){
	manager := []models.Manager{}
	models.DB.Preload("Role").Find(&manager)
	//c.Data["json"] = manager
	//c.ServeJSON()
	c.Data["managerList"] = manager
	c.TplName = "admin/manager/index.html"

}

func (c *ManagerController) Add(){
	// 获取所有角色
	role := []models.Role{}
	models.DB.Find(&role)
	c.Data["roleList"] = role
	c.TplName = "admin/manager/add.html"
}
func (c *ManagerController) DoAdd() {
	//获取数据
	roleId, err1 := c.GetInt("role_id")
	if err1 != nil {
		c.Error("非法请求", "/manager/add")
	}
	username := strings.Trim(c.GetString("username"), " ")
	password := strings.Trim(c.GetString("password"), " ")
	mo
 类似资料: