strconv.FormatInt 类型使用错误

strconv.FormatInt 类型使用错误

不能在strconv.FormatInt的参数中使用a.ID(int类型)作为int64类型

// Link 方法用来生成文章链接
func (a Article) Link() string {
    return route.Name2URL("articles.show", "id", strconv.FormatInt(a.ID, 10))
}
Oyxiaoxi
最佳答案

数据类型转换 Int64 转化为 String

converted_string_variable = strconv.FormatInt(int64(original_int64_varialble), 10)
// Link 方法用来生成文章链接
func (a Article) Link() string {
    return route.Name2URL("articles.show", "id", strconv.FormatInt(int64(a.ID), 10))
}
3年前 评论
讨论数量: 1

数据类型转换 Int64 转化为 String

converted_string_variable = strconv.FormatInt(int64(original_int64_varialble), 10)
// Link 方法用来生成文章链接
func (a Article) Link() string {
    return route.Name2URL("articles.show", "id", strconv.FormatInt(int64(a.ID), 10))
}
3年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!