將資料庫查詢出來的資料轉化成樹形結構

2021-09-16 20:48:21 字數 1531 閱讀 1753

從資料庫查詢的每一條資料都包含id和fid欄位,將獲得的資料轉換成樹形結構

假設從資料庫查詢出來的資料對應的實體類:

public class department 

public department(int id, int fid, string name, listlist)

.......

}

將獲得資料轉化成屬性結構

public class departmentutil 

department.setlist(setchild(department.getid(),rootlist));

}return nodelist;

}public listsetchild(int id, listlist )

}for (department department : childlist)

if (childlist.size()==0)

return childlist;

}}

"citymap"

type

="com.jiucheng.vo.city"

>

="cityid" property=

"cityid"

/>

="cityname" property=

"cityname"

/>

="rootid" property=

"rootid"

/>

="child" property=

"child"

/>

="layer" property=

"layer"

/>

="sort" property=

"sort"

/>

="isopen" property=

"isopen"

/>

"list" oftype=

"com.jiucheng.vo.city"

column

="cityid"

select

="getchildcity"

/>

<

/resultmap>

<

select id=

"findall" resultmap=

"citymap"

>

select

*from city where rootid =

0<

/select

>

<

select id=

"getchildcity" resulttype=

"com.jiucheng.vo.city"

>

select

*from city where rootid =

#<

/select

>

實體類為資料庫的對映對應的實體類

將查詢出來的資料集轉化成JSON格式的類

using system using system.collections using system.collections.generic using system.data using system.globalization using system.linq using system.ref...

json資料轉化成實體 存到資料庫

直接看步驟吧 1.一般我們會呼叫別人給的webservice獲取乙個字串資料。如果為string data x 這個data事實上就是樣例enterpriseinfoentity 的多條記錄 2.把data轉換為jsonarray jsonarray arr new jsonarray arr js...

關於Mysql資料庫時間和查詢出來的時間不一致問題

資料庫記錄的時間 mybatis查詢出來的時間 createtime 2019 06 02 17 39 02.0,lastupdatedtime 2019 06 02 18 49 05.0差了8小時。url用的是servertimezone gmtspring.datasource.url jdbc...