不器小窝 不器小窝
首页
随笔
  • GoLang
  • 前端

    • Vue
    • VuePress
  • 开发工具
  • 系统工具
读吧
  • ToDb (opens new window)
  • goKit (opens new window)
  • 友情链接
  • 免费信息
  • 时间线
  • 关于
GitHub (opens new window)

不器

知行合一
首页
随笔
  • GoLang
  • 前端

    • Vue
    • VuePress
  • 开发工具
  • 系统工具
读吧
  • ToDb (opens new window)
  • goKit (opens new window)
  • 友情链接
  • 免费信息
  • 时间线
  • 关于
GitHub (opens new window)
  • GoLang

    • GoLang 安装
    • Go经验
    • 错误集合
    • 基础库

    • 第三方库

    • Fyne

    • Wails

    • GoFrame

      • Hello GoFrame
      • GoFrame 路由
      • GoFrame问题集合
        • 前言
        • 资源
          • 指定web资源路径
          • 结构目录
          • 配置文件
          • web页面渲染配置文件中的值
        • SQL
          • 模型使用链式操作
      • GoFrame使用jwt
  • Dart

  • Markdown

  • 语言
  • GoLang
  • GoFrame
不器
2022-09-21
目录

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
  1. 在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
  1. 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

结果发现:当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
#GoLang#GoFrame#问题集合#Web静态资源
更新时间: 2023/3/14 13:43:21
GoFrame 路由
GoFrame使用jwt

← GoFrame 路由 GoFrame使用jwt→

最近更新
01
Vue-pure-Admin基础
03-16
02
WebStorm工具使用手册
03-15
03
Windows
03-12
更多文章>
Theme by Vdoing | Copyright © 2022-2023 不器 | 小窝
sitemap icon by Icons8
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式