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

{{.title}}

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

{{$t}}

- {{if ge .score 60}} -

及格

+ {{/* 条件判断示例 - 根据score值判断是否及格 */}} + {{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 .news}} - {{.Title}} - {{.Content}} + {{/* 结构体数据访问示例 - 使用with语句简化结构体属性访问 */}} + {{with .news}} + {{.Title}} + {{.Content}} {{end}}
    - {{.data}} + {{/* 自定义模板函数使用示例 */}} + {{.data}} - {{template "layout/footer"}} + + {{ template "layout/footer"}} {{end}} \ No newline at end of file