开发十年,就只剩下这套Java开发体系了 >>>
前言
好吧,这就是应用于我上一篇文章分页组件使用的后端
一个不严谨的演示案例
承接上文,使用我这篇记录里的不严谨案例
实现
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的数量,是为了前端实现分页效果。