当我使用调试器时,metricId
返回带有所有0 or null
值的度量对象(与输出相同)。
- 我做错了什么 *
The Database connection works.
func GetMetricById(c *gin.Context) {
metricId := c.Param("id")
conn := config.DatabaseConnect()
var obj models.Metric
rows := conn.QueryRow("SELECT * FROM Metric WHERE id = ?", metricId)
err := rows.Scan(&obj.Id, &obj.Sms, &obj.Absence, &obj.Pregnant, &obj.Uwv_notifications, &obj.Wia_dossiers_started, &obj.Employees, &obj.Data_id, &obj.Date, &obj.Type)
if err != nil {
fmt.Println(err.Error())
}
fmt.Println(obj, "Metric Object that is called.")
c.JSON(http.StatusOK, obj)
}
输出:
{
"Id": 0,
"Sms": 0,
"Absence": 0,
"Pregnant": 0,
"Uwv_notifications": 0,
"Wia_dossiers_started": 0,
"Employees": 0,
"Data_id": 0,
"Date": "",
"Type": 0
}
2条答案
按热度按时间c8ib6hqw1#
我认为解决方案可能是使用
metricId := c.Params.ByName("id")
而不是metricId := c.Param("id")
0tdrvxhp2#
[回答]
这样就行了
localhost:8082/billing/getmetricbydataid?data_id=150295
使用此API调用