diff --git a/controller/admin/baseController.go b/controller/admin/baseController.go new file mode 100644 index 0000000..bcf53ee --- /dev/null +++ b/controller/admin/baseController.go @@ -0,0 +1,13 @@ +package admin + +import "github.com/gin-gonic/gin" + +type BaseController struct { +} + +func (con BaseController) Success(c *gin.Context) { + c.String(200, "成功") +} +func (con BaseController) Error(c *gin.Context) { + c.String(200, "失败") +} diff --git a/controller/admin/userController.go b/controller/admin/userController.go index 49f35b1..5115312 100644 --- a/controller/admin/userController.go +++ b/controller/admin/userController.go @@ -3,10 +3,11 @@ package admin import "github.com/gin-gonic/gin" type UserController struct { + BaseController } func (con UserController) Index(c *gin.Context) { - c.String(200, "管理员用户列表") + con.Success(c) } func (con UserController) Show(c *gin.Context) { diff --git a/controller/nannanwu/defaultController.go b/controller/nannanwu/defaultController.go index 36b182e..aacbaf6 100644 --- a/controller/nannanwu/defaultController.go +++ b/controller/nannanwu/defaultController.go @@ -8,7 +8,7 @@ type DefaultController struct { } func (con DefaultController) Index(c *gin.Context) { - c.String(200, "首页") + c.HTML(200, "pages/index", gin.H{}) } func (con DefaultController) Article(c *gin.Context) { c.String(200, "文章详情") diff --git a/templates/pages/index.html b/templates/pages/index.html index 224199c..d0ab3e1 100644 --- a/templates/pages/index.html +++ b/templates/pages/index.html @@ -1,4 +1,3 @@ -{{/* 定义index页面模板 */}} {{define "pages/index"}} @@ -6,63 +5,52 @@ {{.title}} - - - {{template "layout/navbar"}} - {{/* 基本数据输出示例 - 直接渲染标题变量 */}} +

{{.title}}

- {{/* 模板变量定义示例 - 将标题赋值给局部变量t */}} {{$t := .title}}

{{$t}}

- {{/* 条件判断示例 - 根据score值判断是否及格 */}} - {{if ge .score 60}} -

及格

+ {{if ge .score 60}} +

及格

{{else}} -

+

不及格

{{end}} - {{/* 简单数组循环遍历示例 */}} - {{range $key, $value := .hobby}} - + {{range $key, $value := .hobby}} + {{end}} - {{/* 结构体数组循环遍历示例 */}} - {{range $key, $value := .newsList}} - + {{range $key, $value := .newsList}} + {{end}} - {{/* 空数组处理示例 - 当newsList2为空时显示提示信息 */}} {{range $key, $value := .newsList2}} {{else}} -
  • 没有数据
  • +
  • 没有数据
  • {{end}} - {{/* 结构体数据访问示例 - 使用with语句简化结构体属性访问 */}} - {{with .news}} - {{.Title}} - {{.Content}} + {{with .news}} + {{.Title}} + {{.Content}} {{end}}
    - {{/* 自定义模板函数使用示例 */}} - {{.data}} + {{.data}} - - {{ template "layout/footer"}} + {{template "layout/footer"}} {{end}} \ No newline at end of file