From 1a3bd1a6b39383c2bdf11d6249cad70f6f8a5510 Mon Sep 17 00:00:00 2001 From: nannanwu Date: Sat, 21 Feb 2026 12:46:38 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"feat(controller):=20=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E5=9F=BA=E7=A1=80=E6=8E=A7=E5=88=B6=E5=99=A8=E5=8F=8A?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E9=A1=B5=E9=9D=A2=E6=B8=B2=E6=9F=93"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 37c78d9a4eb4c3e17780f11edace5a6a0019f7c1. --- controller/admin/baseController.go | 13 ------- controller/admin/userController.go | 3 +- controller/nannanwu/defaultController.go | 2 +- templates/pages/index.html | 48 +++++++++++++++--------- 4 files changed, 32 insertions(+), 34 deletions(-) delete mode 100644 controller/admin/baseController.go 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