GoFrame问题集合
# 前言
本文针对gf 2.1.4
中使用中遇到的问题进行的记录。
# 资源
# 指定web
资源路径
# 结构目录
点击查看目录结构
.
├── Makefile
├── README.MD
├── api
│ └── v1
│ └── hello.go
├── go.mod
├── go.sum
├── hack
│ ├── config.yaml
│ ├── kit
│ └── plugin
├── internal
│ ├── cmd
│ │ └── cmd.go
│ ├── consts
│ │ └── consts.go
│ ├── controller
│ │ ├── admin
│ │ │ └── index.go
│ │ └── hello.go
│ ├── dao
│ ├── logic
│ ├── model
│ │ ├── do
│ │ └── entity
│ ├── packed
│ │ └── packed.go
│ ├── router
│ │ └── router.go
│ └── service
├── main.go
├── manifest
│ ├── config
│ │ └── config.yaml
│ ├── deploy
│ │ └── kustomize
│ │ ├── base
│ │ │ ├── deployment.yaml
│ │ │ ├── kustomization.yaml
│ │ │ └── service.yaml
│ │ └── overlays
│ │ └── develop
│ │ ├── configmap.yaml
│ │ ├── deployment.yaml
│ │ └── kustomization.yaml
│ └── docker
│ ├── Dockerfile
│ └── docker.sh
├── resource
│ ├── i18n
│ ├── public
│ │ ├── html
│ │ │ └── admin
│ │ │ ├── index.html
│ │ │ └── login.html
│ │ ├── plugin
│ │ └── resource
│ │ ├── css
│ │ │ └── admin
│ │ │ ├── 810.019038a6.css
│ │ │ ├── app.040a8d2a.css
│ │ │ └── loading.css
│ │ ├── image
│ │ │ └── admin
│ │ │ └── bgImg
│ │ │ └── lyfcy.jpg
│ │ └── js
│ │ ├── admin
│ │ │ ├── 810.7d77b430.js
│ │ │ └── app.a08365b1.js
│ │ └── vue
│ │ └── vue.global.js
│ └── template
└── utility
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
- 在
manifest/config/config.yaml
中的server
结构下增加以下代码
# 以项目目录为根节点/
server:
serverRoot: "/resource/public/resource"
viewer:
# 指定web资源
Paths: "resource/public/html"
# 默认页面
DefaultFile: "index.html"
AutoEncode: true
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
html
中引用文件;以引用lyfcy.jpg
为例:<img src="../image/admin/bgImg/lyfcy.jpg">
# 配置文件
# web
页面渲染配置文件中的值
# Config
访问默认的配置管理(config.toml
)对象配置项。
使用方式:
{{.Config.配置项}}
1
# Cookie
访问当前请求的 Cookie 对象参数值。
使用方式:
{{.Cookie.键名}}
1
# Session
访问当前请求的 Session 对象参数值。
使用方式:
{{.Session.键名}}
1
# Query
访问当前 Query String 中的请求参数值。
使用方式:
{{.Query.键名}}
1
# Form
访问当前表单请求参数值。
使用方式:
{{.Form.键名}}
1
# Request
访问当前请求参数值(不区分参数提交方式)。
使用方式:
{{.Request.键名}}
1
# SQL
# 模型使用链式操作
以User
表为例,当我们需要接受前台传过来的时间参数时来讲解
我最开始的时候是按下面方法来写的
// 错误写法
sql := dao.User.Ctx(ctx)
if dateTime != "" {
sql.WhereBetween("create_time",beginDateTime,endDateTime)
}
1
2
3
4
5
2
3
4
5
结果发现:当dateTime
不为空的时候,sql
也没有将条件附加上去,然后看了看文档 (opens new window)发现一段话:
用户模型单例对象
user
可以重复使用,而不用担心被“污染”的问题。在这种链式安全的方式下,我们可以创建一个用户单例对象user
,并且可以重复使用到后续的各种查询中。但是存在多个查询条件时,条件的叠加需要通过模型赋值操作(m = m.xxx)
来实现。
所以猜测是否在模型对象情况下默认加上了Safe
方法,于是改成了下面的方法通过了
// 正确写法
sql := dao.User.Ctx(ctx).Safe(false)
if dateTime != "" {
sql.WhereBetween("create_time",beginDateTime,endDateTime)
}
1
2
3
4
5
2
3
4
5
更新时间: 2023/3/14 13:43:21