1. 程式人生 > >beego4---web項目結構

beego4---web項目結構

test () pla static 成了 shortcut 如果 mlp 相同

技術分享圖片

app.conf
appname = blog1
httpport = 8080
runmode = dev


controllersmy
package controllersmy //跟外面的包名一致

import (
    "github.com/astaxie/beego"
)

type MainController struct {
    beego.Controller //"github.com/astaxie/beego"包裏面的Controller
}

func (c *MainController) Get() {
    //模版
    c.Data["Website"] = "
beego.me22222222222" c.Data["Email"] = "[email protected]" c.TplName = "index.tpl" c.Data["Truecondition"] = true c.Data["falsecondotion"] = false type u struct { Name string Age int Sex string } user := &u{ Name: "name", Age:
19, Sex: "", } c.Data["user"] = user nums := []int{1, 2, 3, 4, 5, 6, 7, 8, 9} c.Data["nums"] = nums //模版變量 c.Data["tempvalue"] = "tempsssvalue" //如果html是安全的,可以直接顯示html內容 c.Data["html"] = "<div>ssss<div>" c.Data["pipe"] = "<div>pipe<div>
" } router.go package routers import ( "blog1/controllersmy" "github.com/astaxie/beego" ) func init() { beego.Router("/", &controllersmy.MainController{}) //"blog1/controllersmy"裏面的 &controllersmy } 頁面 <!DOCTYPE html> <html> <head> <title>Beego</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="shortcut icon" href="" type="image/x-icon" /> <style type="text/css"> *,body { margin: 0px; padding: 0px; } body { margin: 0px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; line-height: 20px; background-color: #fff; } header, footer { width: 960px; margin-left: auto; margin-right: auto; } .logo { background-image: url(‘‘); background-repeat: no-repeat; -webkit-background-size: 100px 100px; background-size: 100px 100px; background-position: center center; text-align: center; font-size: 42px; padding: 250px 0 70px; font-weight: normal; text-shadow: 0px 1px 2px #ddd; } header { padding: 100px 0; } footer { line-height: 1.8; text-align: center; padding: 50px 0; color: #999; } .description { text-align: center; font-size: 16px; } a { color: #444; text-decoration: none; } .backdrop { position: absolute; width: 100%; height: 100%; box-shadow: inset 0px 0px 100px #ddd; z-index: -1; top: 0px; left: 0px; } </style> </head> <body> <header> </header> <div class=""> <!-- 通過.語法獲取c *MainController,c.Data["user"] = user裏面的數據 --> {{if .Truecondition}} true Truecondition {{end}} </div> <div class=""> {{.user.Name}}; {{.user.Age}}; {{.user.Sex}} </div> <div class=""> <!-- 前綴相同使用with進行省略寫法 --> {{with .user}} {{.Name}}; {{.Age}}; {{.Sex}}; {{end}} </div> <div class=""> {{.nums}} <!-- 循環打印數組 --> {{range .nums}} {{.}} {{end}} </div> <div class=""> <!-- 模版變量 ,$a就是一個模版變量,並且賦值了,--> {{$a := .tempvalue}} {{$a}} </div> {{.html}} {{str2html .html}}<!-- string轉成了html --> <div class=""> {{.pipe | htmlquote}} </div> <div class=""> {{template "test"}}<!-- 使用模版 --> </div> <footer> </footer> <script src="/static/js/reload.min.js"></script> </body> </html> {{define "test"}}<!-- 模版定義 --> <div> this is temlpe <div> {{end}} main.go package main import ( _ "blog1/routers" "github.com/astaxie/beego" ) func main() { beego.Run() }

beego4---web項目結構