This commit is contained in:
vipg
2025-11-11 18:27:51 +08:00
parent 8d6c211767
commit 0ea63d2ba7
3 changed files with 8 additions and 7 deletions

View File

@@ -139,13 +139,14 @@ func ReadHandler(c *gin.Context) {
// 计算分页偏移量
offset := (page - 1) * pageSize
// 拼接分页SQL
querySQL := baseSQL + " ORDER BY country_id LIMIT $"+strconv.Itoa(paramIndex)+" OFFSET $"+strconv.Itoa(paramIndex+1)
// 拼接分页SQL使用fmt.Sprintf更清晰
querySQL := fmt.Sprintf("%s ORDER BY country_id LIMIT $%d OFFSET $%d", baseSQL, paramIndex, paramIndex+1)
args = append(args, pageSize, offset)
// 查询总条数
// 查询总条数(修正参数传递方式)
var total int64
err = db.DB.QueryRow(countSQL, args...[:len(args)-2]...).Scan(&total)
countArgs := args[:len(args)-2] // 排除分页参数
err = db.DB.QueryRow(countSQL, countArgs...).Scan(&total)
if err != nil {
zap.L().Error("❌ 查询总条数失败",
zap.String("req_id", reqID),