mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
improve perameter parsing for ghttp.Server
This commit is contained in:
34
.example/database/gdb/mysql/gdb_update_field.go
Normal file
34
.example/database/gdb/mysql/gdb_update_field.go
Normal file
@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/gogf/gf/os/gfile"
|
||||
|
||||
"github.com/gogf/gf/encoding/gjson"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
)
|
||||
|
||||
func main() {
|
||||
db := g.DB()
|
||||
table := "medicine_clinics_upload_yinchuan"
|
||||
list, err := db.Table(table).All()
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
panic(err)
|
||||
}
|
||||
content := ""
|
||||
for _, item := range list {
|
||||
if j, err := gjson.DecodeToJson(item["upload_data"].String()); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
s, _ := j.ToJsonIndentString()
|
||||
content += item["id"].String() + "\t" + item["medicine_clinic_id"].String() + "\t"
|
||||
content += s
|
||||
content += "\n\n"
|
||||
//if _, err := db.Table(table).Data("data_decode", s).Where("id", item["id"].Int()).Update(); err != nil {
|
||||
// panic(err)
|
||||
//}
|
||||
}
|
||||
}
|
||||
gfile.PutContents("/Users/john/Temp/medicine_clinics_upload_yinchuan.txt", content)
|
||||
}
|
||||
@ -8,7 +8,6 @@ import (
|
||||
|
||||
func main() {
|
||||
db := g.DB()
|
||||
// 开启调试模式,以便于记录所有执行的SQL
|
||||
db.SetDebug(true)
|
||||
|
||||
r, e := db.Table("test").Where("id IN (?)", []interface{}{1, 2}).All()
|
||||
|
||||
16
.example/net/ghttp/server/form/form.go
Normal file
16
.example/net/ghttp/server/form/form.go
Normal file
@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/net/ghttp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.BindHandler("/", func(r *ghttp.Request) {
|
||||
g.Dump(r.GetPostMap())
|
||||
r.Response.WriteTpl("form.html")
|
||||
})
|
||||
s.SetPort(8199)
|
||||
s.Run()
|
||||
}
|
||||
30
.example/net/ghttp/server/form/form.html
Normal file
30
.example/net/ghttp/server/form/form.html
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>form test</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>form1</h1>
|
||||
<form action="?" method="post" enctype="multipart/form-data">
|
||||
<p><input type="text" name="input1" value="1"/></p>
|
||||
<p><input type="text" name="input2" value="2"/></p>
|
||||
<p><input type="text" name="array1" value="3"/></p>
|
||||
<p><input type="text" name="array1" value="4"/></p>
|
||||
<p><input type="text" name="array2[]" value="5"/></p>
|
||||
<p><input type="text" name="array2[]" value="6"/></p>
|
||||
<p><input type="text" name="map[a]" value="7"/></p>
|
||||
<p><input type="text" name="map[b]" value="8"/></p>
|
||||
<p><input type="password" name="password1" value="9"/></p>
|
||||
<input type="submit" value="Submit" />
|
||||
</form>
|
||||
|
||||
<h1>form2</h1>
|
||||
<form action="?" method="post" enctype="application/x-www-form-urlencoded">
|
||||
<p><input type="text" name="input[a]" value="1"/></p>
|
||||
<p><input type="text" name="input[b]" value="2"/></p>
|
||||
<p><input type="text" name="array" value="3"/></p>
|
||||
<p><input type="text" name="array" value="4"/></p>
|
||||
<p><input type="password" name="password2" value="5"/></p>
|
||||
<input type="submit" value="Submit" />
|
||||
</form>
|
||||
</body>
|
||||
@ -2,10 +2,15 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/gogf/gf/frame/g"
|
||||
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(gstr.CamelCase("userLoginLog.bak"))
|
||||
m, _ := gstr.Parse("map[a]=1&map[b]=2")
|
||||
g.Dump(m)
|
||||
fmt.Println(reflect.TypeOf(m["map"].(map[string]interface{})["b"]))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user