1 回答
TA贡献1772条经验 获得超5个赞
像这样的东西:
app.Get("/lottery/{id:int}", func(ctx iris.Context) {
id1 := ctx.Params().GetIntDefault("id", 0)
stmtOut, err := db.Prepare("select lottery_name, lottery_description from lottery_table where id = ?")
if err != nil {
panic(err.Error())
}
defer stmtOut.Close()
lot := Lottery{Id: id1}
err1 := stmtOut.QueryRow(id1).Scan(&lot.Lottery, &lot.Description)
if err != nil {
panic(err1.Error())
}
stmtOut1, err := db.Query("select id, reward_name, reward_description, reward_asset, reward_asset_name from rewards_table where lottery_id = ?", id1)
if err != nil {
panic(err.Error())
}
defer stmtOut1.Close()
for stmtOut1.Next() {
rew := Rew{}
err2 := stmtOut1.Scan(&rew.Id, &rew.RewardName, &rew.Description, &rew.Asset, &rew.AssetName)
if err2 != nil {
panic(err.Error())
}
lot.Reward = append(lot.Reward, rew)
}
ctx.JSON(lot)
})
- 1 回答
- 0 关注
- 110 浏览
添加回答
举报