完整代码
// 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