咱們先看效果,再說說怎麼弄!ide
咱們來試試如何用,我也寫了一個測試數據。測試
而後咱們在Junit中測試:spa
- @Test
- public void joinTable() {
- JingZongDB jzdb=new JingZongDB();
- DataTable dt1=jzdb.getDataTable("select * from newsType");
- DataTable dt2=jzdb.getDataTable("select * from news");
- DataTable dt=DataTable.joinTable(dt1, dt2, "id", "typeid");
- wl("新聞類型表:"+dt1.getRow().size());
- DataTable.outTable(dt1); http://open.189works.com/product/product.htm
- wl("新聞表:"+dt2.getRow().size());
- DataTable.outTable(dt2);
- wl("合併後:"+dt.getRow().size());
- DataTable.outTable(dt);
- }
- private void wl(String s) {
- System.out.println(s);
- }
最後結果爲:htm
- 新聞類型表:4
- id:1 typeName:學生工做
- id:2 typeName:通知公告
- id:3 typeName:招生簡章
- id:4 typeName:教務信息
- 新聞表:16
- id:1 typeid:1 newsName:學生工做1
- id:2 typeid:1 newsName:學生工做2
- id:3 typeid:1 newsName:學生工做3
- id:4 typeid:1 newsName:學生工做4
- id:5 typeid:2 newsName:通知公告1
- id:6 typeid:2 newsName:通知公告2
- id:7 typeid:2 newsName:通知公告3
- id:8 typeid:2 newsName:通知公告4
- id:9 typeid:3 newsName:招生簡章1
- id:10 typeid:3 newsName:招生簡章2
- id:11 typeid:3 newsName:招生簡章3
- id:12 typeid:3 newsName:招生簡章4
- id:13 typeid:4 newsName:教務信息1
- id:14 typeid:4 newsName:教務信息2
- id:15 typeid:4 newsName:教務信息3
- id:16 typeid:4 newsName:教務信息4
- 合併後:16
- id:1 typeName:學生工做 id:1 typeid:1 newsName:學生工做1
- id:1 typeName:學生工做 id:2 typeid:1 newsName:學生工做2
- id:1 typeName:學生工做 id:3 typeid:1 newsName:學生工做3
- id:1 typeName:學生工做 id:4 typeid:1 newsName:學生工做4 http://open.189works.com/product/product.htm
- id:2 typeName:通知公告 id:5 typeid:2 newsName:通知公告1
- id:2 typeName:通知公告 id:6 typeid:2 newsName:通知公告2
- id:2 typeName:通知公告 id:7 typeid:2 newsName:通知公告3
- id:2 typeName:通知公告 id:8 typeid:2 newsName:通知公告4
- id:3 typeName:招生簡章 id:9 typeid:3 newsName:招生簡章1
- id:3 typeName:招生簡章 id:10 typeid:3 newsName:招生簡章2
- id:3 typeName:招生簡章 id:11 typeid:3 newsName:招生簡章3
- id:3 typeName:招生簡章 id:12 typeid:3 newsName:招生簡章4
- id:4 typeName:教務信息 id:13 typeid:4 newsName:教務信息1
- id:4 typeName:教務信息 id:14 typeid:4 newsName:教務信息2
- id:4 typeName:教務信息 id:15 typeid:4 newsName:教務信息3
- id:4 typeName:教務信息 id:16 typeid:4 newsName:教務信息4