1 Star 0 Fork 0

叶明志 / golang练习

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pagesHandler.go 2.96 KB
一键复制 编辑 原始数据 按行查看 历史
package controller
import (
"GolangLearnPractice1/bookstore2/dao"
"GolangLearnPractice1/bookstore2/model"
"net/http"
"strconv"
"text/template"
)
// //GetPages 得到商品信息
// func GetPages(w http.ResponseWriter, r *http.Request) {
// t := template.Must(template.ParseFiles("view/main.html"))
// t.Execute(w, "")
// }
//GetPagesByPrice 根据价格得到商品的信息
func GetPagesByPrice(w http.ResponseWriter, r *http.Request) {
flag, session := dao.IsLogin(r)
if flag {
//已经成功登录
//从浏览器得到最小、最大价格,页面序号
minPrice := r.FormValue("minPrice")
maxPrice := r.FormValue("maxPrice")
pageNo := r.FormValue("pageNo")
if pageNo == "" {
pageNo = "1"
}
//构造要显示的页面内容
var page *model.Page
//设定一页显示多少图书
var pageSize int64 = 4
//装换pageNo格式
ipageNo, _ := strconv.ParseInt(pageNo, 10, 64)
if (maxPrice == "" && minPrice == "") || (maxPrice == "0" && minPrice == "0") {
//用户没有进行价格筛选
page, _ = dao.GetPageNo(ipageNo, pageSize)
} else {
//用户进行了价格筛选
//对从浏览器拿来的数据进行格式解析
fMinPrice, _ := strconv.ParseFloat(minPrice, 64)
fMaxPrice, _ := strconv.ParseFloat(maxPrice, 64)
page, _ = dao.GetPageNoByPrice(ipageNo, pageSize, fMinPrice, fMaxPrice)
}
page.IsLogin = true
page.Username = session.UserName
t := template.Must(template.ParseFiles("view/main.html"))
t.Execute(w, page)
} else {
//尚未登录
//从浏览器得到最小、最大价格,页面序号
minPrice := r.FormValue("minPrice")
maxPrice := r.FormValue("maxPrice")
pageNo := r.FormValue("pageNo")
if pageNo == "" {
pageNo = "1"
}
//构造要显示的页面内容
var page *model.Page
//设定一页显示多少图书
var pageSize int64 = 4
//装换pageNo格式
ipageNo, _ := strconv.ParseInt(pageNo, 10, 64)
if (maxPrice == "" && minPrice == "") || (maxPrice == "0" && minPrice == "0") {
//用户没有进行价格筛选
page, _ = dao.GetPageNo(ipageNo, pageSize)
} else {
//用户进行了价格筛选
//对从浏览器拿来的数据进行格式解析
fMinPrice, _ := strconv.ParseFloat(minPrice, 64)
fMaxPrice, _ := strconv.ParseFloat(maxPrice, 64)
page, _ = dao.GetPageNoByPrice(ipageNo, pageSize, fMinPrice, fMaxPrice)
}
page.IsLogin = false
page.Username = ""
t := template.Must(template.ParseFiles("view/main.html"))
t.Execute(w, page)
}
}
//GetPageBooks 得到图书页面
func GetPageBooks(w http.ResponseWriter, r *http.Request) {
//从浏览器得到页面ID,如果没有,设为第1页
pageNo := r.FormValue("pageNo")
ipageNo, _ := strconv.ParseInt(pageNo, 10, 64)
if ipageNo < 1 {
ipageNo = 1
}
//设置页面显示图书的数量
var pageSize int64 = 4
//根据页面ID拿到页面
page, _ := dao.GetPageNo(ipageNo, pageSize)
if page != nil {
t := template.Must(template.ParseFiles("view/pages/manager/book_manager.html"))
t.Execute(w, page)
}
}
Go
1
https://gitee.com/yemingzhi/GolangLearnPractice1.git
git@gitee.com:yemingzhi/GolangLearnPractice1.git
yemingzhi
GolangLearnPractice1
golang练习
2bf136849dce

搜索帮助