主题
文章
项目
资源
图书
Go网址导航
下载
官方文档
英文文档
中文文档
标准库中文版
Go指南
注册
登录
首页
会员
867342143的信息
TA的收藏
初级会员
第 19172 位会员
ID:
867342143
注册时间:
2018-06-06 14:48:56
是否在线:
Offline
财富:
20
7
更多>>
最近发布的主题
Go问与答
在win xp 运行报错 求大佬 看看 这是啥错误
at
2019-06-11 16:41:45
Go语言
Go语言官方中文文档(CHM版)全网首发
at
2018-09-10 16:50:32
更多>>
最近发布的文章
暂无
更多>>
最近分享的资源
暂无
更多>>
最近发布的项目
暂无
更多>>
最近的评论
暂无
最新主题
|
最新资源
|
最新评论
niuhe - IDL 生成代码,前端协议, 页面和文档插件
Vite5+Electron聊天室|electron31跨平台仿微信EXE客户端|vue3聊天程序
Tauri2.0-Vue3OS桌面端os平台|tauri2+vite6+arco电脑版OS管理系统
flutter3-dymall仿抖音直播商城|Flutter3.27短视频+直播+聊天App实例
结构体的切片(slice of struct)不等于它实现的接口的切片(slice of interface)?
如何在 Go 中使用管道连接多个命令?
如何在 Go 程序中打包静态资源?
如何在 Go 中使用 C++?
在 Go 中取消阻塞操作
Golang单元测试
LIGUANGYAO
大约9小时之前
在
[go 面试] 接口测试的方法与技巧
中评论
学习了,能下载[系统源码](http://doofuu.com/)吗,有go开发的[小程序案例](http://doofuu.com/article/4156206.html)吗,或者能[免费下载源码](https://free.doofuu.com)能也行
LIGUANGYAO
大约9小时之前
在
手把手用 Go 带你写一个小工具
中评论
学习了,能下载[系统源码](http://doofuu.com/)吗,有go开发的[小程序案例](http://doofuu.com/article/4156206.html)吗,或者能[免费下载源码](https://free.doofuu.com)能也行
LIGUANGYAO
大约9小时之前
在
OpenGL渲染引擎-设计与实践教程
中评论
学习了,能下载[系统源码](http://doofuu.com/)吗,有go开发的[小程序案例](http://doofuu.com/article/4156206.html)吗,或者能[免费下载源码](https://free.doofuu.com)能也行
LIGUANGYAO
大约9小时之前
在
选择适合微服务的编程语言
中评论
学习了,能下载[系统源码](http://doofuu.com/)吗,有go开发的[小程序案例](http://doofuu.com/article/4156206.html)吗,或者能[免费下载源码](https://free.doofuu.com)能也行
LIGUANGYAO
大约9小时之前
在
[go 面试] 雪花算法与分布式ID生成
中评论
学习了,能下载[系统源码](http://doofuu.com/)吗,有go开发的[小程序案例](http://doofuu.com/article/4156206.html)吗,或者能[免费下载源码](https://free.doofuu.com)能也行
LIGUANGYAO
大约9小时之前
在
手把手教你用Go语言实现缓存系统
中评论
学习了,能下载[系统源码](http://doofuu.com/)吗,有go开发的[小程序案例](http://doofuu.com/article/4156206.html)吗,或者能[免费下载源码](https://free.doofuu.com)能也行
LIGUANGYAO
大约9小时之前
在
Playwright+Python自动化测试课程
中评论
学习了,能下载[系统源码](http://doofuu.com/)吗,有go开发的[小程序案例](http://doofuu.com/article/4156206.html)吗,或者能[免费下载源码](https://free.doofuu.com)能也行
LIGUANGYAO
大约9小时之前
在
[完结40周]物联网/嵌入式全能工程师(提薪优选)
中评论
学习了,能下载[系统源码](http://doofuu.com/)吗,有go开发的[小程序案例](http://doofuu.com/article/4156206.html)吗,或者能[免费下载源码](https://free.doofuu.com)能也行
cllgeek
5天之前
在
Go每日一题(17)
中评论
打卡
joanswei
6天之前
在
golang 无限级树状结构
中评论
package main import ( //"encoding/json" "encoding/json" "fmt" ) type Datanode struct { Id int `json:"id"` PId int `json:"pid"` Name string `json:"name"` Child []*Datanode `json:"child"` } var Jsondata []byte //存储json数据 func main() { Data := make([]Datanode, 0) //存储所有初始化struct var a Datanode a.Id = 0 a.PId = -1 a.Name = "目录" Data = append(Data, a) a.Id = 1 a.PId = 0 a.Name = "一、水果" Data = append(Data, a) a.Id = 2 a.PId = 1 a.Name = "1.苹果" Data = append(Data, a) a.Id = 3 a.PId = 1 a.Name = "2.香蕉" Data = append(Data, a) a.Id = 4 a.PId = 0 a.Name = "二、蔬菜" Data = append(Data, a) a.Id = 5 a.PId = 4 a.Name = "1.芹菜" Data = append(Data, a) a.Id = 6 a.PId = 4 a.Name = "2.黄瓜" Data = append(Data, a) a.Id = 7 a.PId = 6 a.Name = "(1)黄瓜特点" Data = append(Data, a) a.Id = 8 a.PId = 4 a.Name = "3.西红柿" Data = append(Data, a) a.Id = 9 a.PId = 0 a.Name = "三、关系" Data = append(Data, a) var data []*Datanode data = make([]*Datanode, 0) for i, _ := range Data { var a *Datanode a = &Data[i] data = append(data, a) } node := &Data[4] //父节点 maketree(data, node) //调用生成tree transformjson(node) //转化为json jsontotree(Jsondata) //json 转为struct } func maketree(Data []*Datanode, root *Datanode) { // 创建一个哈希表,用于快速查找子节点 childMap := make(map[int][]*Datanode) for _, node := range Data { childMap[node.PId] = append(childMap[node.PId], node) } // 递归构建树 buildTree(root, childMap) } func buildTree(node *Datanode, childMap map[int][]*Datanode) { // 查找当前节点的子节点 if children, exists := childMap[node.Id]; exists { node.Child = append(node.Child, children...) // 递归处理子节点 for _, child := range children { buildTree(child, childMap) } } } func transformjson(Data *Datanode) { //转为json Jsondata, _ = json.Marshal(Data) fmt.Println(string(Jsondata)) } func jsontotree(jsondata []byte) { //json转struct var a Datanode err := json.Unmarshal(jsondata, &a) fmt.Println("22222222222222", string(jsondata)) if err != nil { fmt.Println(err) } else { fmt.Println(a.Id, a.PId, a.Name) for _, v := range a.Child { fmt.Println(*v) } } } 你这个存在很严重的性能问题,如果有10级,数据量很大,你这个就循环不过来了,如果写在接口里就不满足开发环境了,其实有两种情况优化一个使用mysql8.0以后得无限父级查询,一个是代码优化
X
登录和大家一起探讨吧
用户名
密码
记住登录状态
登录
GitHub 登录
忘记密码?
还不是会员
现在注册
最近的评论
暂无