1.前期处理
包括默认引擎设置,具体如下,此部分仅供参考
// 设置gin引擎的默认配置
func setDefaultEngine(router *gin.Engine) {
router.SetFuncMap(template.FuncMap{
"safe": func(str string) template.HTML {
return template.HTML(str)
},
"SJS": func(str string) template.JS {
return template.JS(str)
},
"SCSS": func(str string) template.CSS {
return template.CSS(str)
},
})
//静态文件渲染
router.Static("/xxx", "./creditBank/statics")
router.LoadHTMLGlob("./creditBank/templates/*")
}
2.传数组
下面是一个测试数组
arr := []string{}
arr = append(arr, "a")
arr = append(arr, "b")
arr = append(arr, "c")
arr = append(arr, "d")
c.HTML(http.StatusOK, "course_edit.html", gin.H{
"permission": permission,
"teachers": arr,
})
3.HTML接收
<select type="text" id="machine_room" name="machine_room" required=""
autocomplete="off" class="layui-input" lay-verify="required" lay-search="">
<option value=""></option>
{{ range $i, $v := .teachers }}
<option value="{{ $v | safe }}">{{ $v | safe}}</option>
{{ end }}
</select>