8种机械键盘轴体对比
本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选?
在html中使用数据的一些方法
这里可以看到具体的文档 传送门
for 循环不会得到index1
2
3
4
5
6
7
8
9
10
11{{range .articles}} 循环.articles数据
{{.Title}} 查看详情 {{.Time}}{{.Count}} 删除 编辑财经新闻{{end}}得到index,value1
2
3
4{{range $index ,$val := .articles}}
{{end}}
格式化时间
当从代码中取出时间后显示这样:2019-09-17 17:37:01 +0800 CST 很明显不是我想要的格式,需要进行格式化。1
2
{{.Time.Format "2006-01-02 15:04:05"}} 出来后的结果就是我们想要的格式了2019-09-17 17:37:01
在分页中遇到的知识点
具体看 这里使用视图代码(在html中进行调用go代码)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
上一页 下一页其中上面 | 表示 赋值的操作 意思是 将.pageIndex 带入到名字为 showPrePage的方法中去。
func (pageIndex int) (result int) {
result = pageIndex - 1
if result <= 0 {
result = 1
}
return
}
//计算下一页
func HandleNextPage(pageIndex int) (result int) {
result = pageIndex + 1
return
}
if else gt(大于) lt(小于)1
2
3
4
5
6
7
8
9
10
11{{if gt .pageIndex 1}} gt 大于的意思 如果.pageIndex > 1 才会显示链接
上一页{{else}}
上一页{{end}}
---
{{if lt .pageIndex .totalPage }} lt 小于的意思 如果.pageIndex < totalPage 才会显示链接
下一页{{else}}
下一页{{end}}
gt(大于) lt(小于) gte(大于等于) lte(小于等于)1{{if gt .pageIndex 1}}
等于compare、eq1
2
3
4
5
6
7
8
9{{if compare .pageIndex 1 }} 如果.pageIndex==1
首页{{end}}
---
{{if eq .pageIndex 1 }}
首页{{end}}
不等于1
2
3{{if ne .pageIndex 1 }} ne 为不等于
首页{{end}}
template引用代码1{{template "comm/header.html" .}} 引用代码到当前的位置 . 表示传递当前参数到子模板
Layout这个是template类型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
47func (this *ShowLayoutContent) ShowLayoutContent() {
//需要渲染的目标布局
this.Layout = "layout.html"
//将当前的布局渲染到目标布局
this.TplName="main.html"
}
---
目标目标为layout.html
后台管理页面{{.LayoutContent}} 注意这里就是需要将其他布局引入的地方。必须这样写
LayoutSections当给layout.html中设置局部的信息的时候。比如每个界面都有自己的标题,这个时候需要从每个controllers中给layout.html发送特定的title。这个时候就用到了LayoutSections1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
181、layout.html
...
{{.title_text}} 这里就是每个界面要显示不同的信息
...
2、title_text.html 重新建立
{{.title}}3、LayoutSections 局部中设定
func (this *ShowLayoutContent) ShowLayoutContent() {
this.Layout = "layout.html"
this.LayoutSections = map[string]string{}
this.LayoutSections["title_text"] = "title_text.html" //定义html
this.Data["title"]="首页"
this.TplName = "main.html"
}
$.注意的地方(在range中使用控制器中的变量时)
当在range的代码中使用.的时候,注意如果想使用控制器里面的代码需要使用$1
2
3
4
5
6
7
8
9
10
11
12
13
{{range .articleTypes}}
{{if compare .TypeName $.CurrentTypeName}}
{{.TypeName}}
{{else}}
{{.TypeName}}
{{end}}
{{end}}
上面代码中,在range中想使用控制其中的CurrentTypeName,这个时候需要用到$.来引入。
Cookie的注意点将数据保存到浏览器,可以设置储存的时长,一般用于记录账号、是否保存等不敏感的信息。注意保持的数据不能是中文1
2
3
4
5
6
7
8
9
10
11
12
13
14
15//保持cookie
check := this.GetString("remember")
if check == "on" {
//记住用户名
this.Ctx.SetCookie("userName", userName, time.Second*100, "/")
} else {
this.Ctx.SetCookie("userName", "", -1, "/")
}
//获取cookie
cookie := this.Ctx.GetCookie("userName")
logs.Info("cookie---->", cookie)
if cookie != "" {
this.Data["userName"] = cookie
}
Session 和 路由过滤器存储用户信息,beego默认把数据存在后台 内存中。临时存储数据,如果浏览器关闭,session数据失效。当在浏览器上
使用错误界面当404的时候,直接使用beego中定义好的错误模板1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
181、定义ErrorController
type ErrorController struct {
BaseController
}
2、404处理
func (this *ErrorController) Error404() {
this.Data["content"] = "page not found---404"
this.TplName = "error/404.html"
}
3、500处理
func (this *ErrorController) Error500() {
err, _ := this.Data["error"].(error)
this.Data["err"] = err
this.TplName = "error/500.html"
}
4、在router注册
//错误处理的界面
beego.ErrorController(&controllers.ErrorController{})
当要出发500错误的时候,需要调用controll.Abort(‘500’)