go-xorm实现分页

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

前言

好吧,这就是应用于我上一篇文章分页组件使用的后端

一个不严谨的演示案例

承接上文,使用我这篇记录里的不严谨案例

实现

func PageGetAll(engine *xorm.Engine,limit,index int)(addrList []*MailBoxAddress,total int64,err error){
    total,err =engine.Table("mailboxes").Alias("box").
        Join("INNER",[]string{"buildings","mailbuilding"},"box.building_id = mailbuilding.id").
        Join("INNER","links","box.id = links.mailbox_id").
        Join("INNER","buildings","links.building_id = buildings.id").
        Count(new(MailBoxAddress))
    if err !=nil{
        return
        }
    err = engine.Table("mailboxes").Alias("box").Select("box.*, mailbuilding.addr,buildings.*,links.*").
        Join("INNER",[]string{"buildings","mailbuilding"},"box.building_id = mailbuilding.id").
        Join("INNER","links","box.id = links.mailbox_id").
        Join("INNER","buildings","links.building_id = buildings.id").
        Limit(limit,index*limit).Find(&addList)
    return
}

小结

之所以在代码中返回所有item的数量,是为了前端实现分页效果。

转载于:https://my.oschina.net/u/3703365/blog/1824135

你可能感兴趣的:(golang,前端,python,ViewUI)