<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                package main import ( // "fmt" "database/sql" "io" "log" "net/http" "text/template" "time" "github.com/ziutek/mymysql/godrv" ) // 留言結構 type Liuyan struct { Id int Name string Content string Time int } // 顯示留言時間 func (l Liuyan) ShowTime() string { t := time.Unix(int64(l.Time), 0) return t.Format("2006-01-02 15:04:05") } func main() { godrv.Register("SET NAMES utf8") // 連接數據庫 db, err := sql.Open("mymysql", "tcp:127.0.0.1:3306*go/root/123456") if err != nil { panic(err) } defer db.Close() // 準備模板 tpl, err := template.New("liuyanbook").Parse(html) if err != nil { panic(err) } // 顯示留言頁面 / requestList := func(w http.ResponseWriter, req *http.Request) { // 查詢數據 rows, err := db.Query("select * from liuyan") if err != nil { log.Fatal(err) } defer rows.Close() // 獲取數據 lys := []Liuyan{} for rows.Next() { ly := Liuyan{} err := rows.Scan(&ly.Id, &ly.Name, &ly.Content, &ly.Time) if nil != err { log.Fatal(err) } lys = append(lys, ly) } // 顯示數據 err = tpl.ExecuteTemplate(w, "list", lys) if err != nil { log.Fatal(err) } } // 留言頁面 /liuyan requestLiuyan := func(w http.ResponseWriter, req *http.Request) { err := req.ParseForm() if err != nil { log.Fatal(err) } if "POST" == req.Method { if len(req.Form["name"]) < 1 { io.WriteString(w, "參數錯誤!\n") return } if len(req.Form["content"]) < 1 { io.WriteString(w, "參數錯誤!\n") return } name := template.HTMLEscapeString(req.Form.Get("name")) content := template.HTMLEscapeString(req.Form.Get("content")) // sql語句 sql, err := db.Prepare("insert into liuyan(name, content, time) values(?, ?, ?)") if err != nil { log.Fatal(err) } defer sql.Close() // sql參數,并執行 _, err = sql.Exec(name, content, time.Now().Unix()) if err != nil { log.Fatal(err) } // 跳轉 w.Header().Add("Location", "/") w.WriteHeader(302) // 提示信息 io.WriteString(w, "提交成功!\n") return } err = tpl.ExecuteTemplate(w, "liuyan", nil) if err != nil { log.Fatal(err) } } http.HandleFunc("/", requestList) http.HandleFunc("/liuyan", requestLiuyan) err = http.ListenAndServe(":12345", nil) if err != nil { log.Fatal("ListenAndServe: ", err) } } // 網頁模板 var html string = `{{define "list"}}{{/* 留言列表頁面 */}}<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <p><a href="/liuyan">給我留言</a></p> <table> {{range .}} <tr> <td>{{.Id}}</td><td>{{.Name}}</td><td>{{.Content}}</td><td>{{.ShowTime}}</td> </tr> {{end}} </table> </body> </html>{{end}} {{define "liuyan"}}{{/* 發布留言頁面 */}}<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <form method="post"> 姓名:<input type="text" name="name" /><br> 內容:<input type="text" name="content" /><br> <input type="submit" value="提交" /> </form> </body> </html>{{end}}`
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看