0

我有一个简单的语句,它通过调用表SELECT中的所有列。couponwho_added

代码:

func CouponByUserID(c *gin.Context) {
    fmt.Println("CouponByUserID()")
    lCoupon := []model.Coupon{}
    whoAdded := c.PostForm("whoAdded")
    fmt.Println("whoAdded: " + whoAdded)

    var sqlSel = ""
    sqlSel = sqlSel + " SELECT * FROM coupon WHERE who_added = ? "

    fmt.Println("sqlSel")
    fmt.Println(sqlSel)
    _, err := dbmap.Select(&lCoupon, sqlSel, whoAdded)

    if err == nil || lCoupon != nil {
        fmt.Println("got result")
        fmt.Println(lCoupon)
        c.Header("Content-Type", "application/json")
        c.JSON(http.StatusOK, lCoupon)
    } else {
        fmt.Println("coupon not found")
        c.JSON(404, gin.H{"error": "coupon not found"})
    }
}

优惠券型号:

type Coupon struct {
    CouponID          int64   `db:"coupon_id, primarykey, autoincrement"`
    CouponName        string  `db:"coupon_name,omitempty"`
    CouponCode        string  `db:"coupon_code,omitempty"`
    Description       string  `db:"description,omitempty"`
    Status            string  `db:"status,omitempty"`
    CampaignStart     int64   `db:"campaign_start,omitempty"`
    CampaignEnd       int64   `db:"campaign_end,omitempty"`
    SourceType        string  `db:"source_type,omitempty"`
    Preview           string  `db:"preview,omitempty"`
    CouponFormat      string  `db:"coupon_format,omitempty"`
    PreviewType       string  `db:"preview_format,omitempty"`
    Display           string  `db:"display,omitempty"`
    DisplayType       string  `db:"display_format,omitempty"`
    Width             float64 `db:"width,omitempty"`
    Height            float64 `db:"height,omitempty"`
    WhoAdded          int     `db:"who_added,omitempty"`
    WhenAdded         int     `db:"when_added,omitempty"`
    WhoUpdated        int     `db:"who_updated,omitempty"`
    WhenUpdated       int     `db:"when_updated,omitempty"`
    TermsAndCondition string  `db:"terms_and_condition,omitempty"`
    CouponLocation    string  `db:"coupon_location,omitempty"`
    BusID             string  `db:"bus_id,omitempty"`
    ImgCoupon         string  `db:"img_coupon,omitempty"`
}

结果: 正如您在此处看到的,即使我的表有数据,它也是空的。

邮差

问题:我表上的数据未显示在结果中。

我试图在 MySQL 工作台上查询相同的语句,它工作得很好。

我哪里做错了?

4

0 回答 0