From ab2c34275d9527a708330cd6beea1932d13e6b99 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 05 十月 2023 14:46:53 +0800 Subject: [PATCH] 将JSON映射成实体类 --- src/main/java/com/smartearth/poiexcel/controller/EntController.java | 2 src/main/java/com/smartearth/poiexcel/config/InitConfig.java | 21 ++++- src/main/java/com/smartearth/poiexcel/entity/EntResult.java | 162 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/smartearth/poiexcel/config/InitConfig.java b/src/main/java/com/smartearth/poiexcel/config/InitConfig.java index 1dc8ce4..7e3e9db 100644 --- a/src/main/java/com/smartearth/poiexcel/config/InitConfig.java +++ b/src/main/java/com/smartearth/poiexcel/config/InitConfig.java @@ -2,6 +2,8 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.smartearth.poiexcel.entity.EntEntity; +import com.smartearth.poiexcel.entity.EntResult; import com.smartearth.poiexcel.entity.Result; import com.smartearth.poiexcel.entity.TokenResult; import org.apache.commons.logging.Log; @@ -9,6 +11,8 @@ import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; + +import java.util.List; /** * 鍒濆鍖栧畬鎴愰厤缃被 @@ -30,12 +34,21 @@ } } + /** + * 娴嬭瘯 + */ private void test() { - String json = "{\"success\":true,\"code\":200,\"message\":\"鎴愬姛\",\"data\":{\"ctoken\":\"ZmYxZTgyN2QxZTYyNDMxMDhjZjgzNDNiNDZiN2RjMDVAYTc3ZmFlOGE5ZGM0OGQ1Y2ZmODY4ZTFmNWYwZTEzM2E=\",\"userInfo\":{\"loginLogId\":\"1ab1675c3632428a84dc0ebe579cd66f\",\"phoneNumber\":\"\",\"displayName\":\"鏃剁┖涓�寮犲浘\",\"userMail\":\"\",\"departLevel\":\"5-1\",\"id\":\"ff1e827d1e6243108cf8343b46b7dc05\",\"userID\":\"shikong001\",\"uniqueID\":\"\",\"departName\":\"姹借溅鍜屾櫤鑳藉埗閫犱骇涓氫笓鐝璡"},\"expires\":3600,\"roles\":[]}}"; - Result rs = JSON.parseObject(json, Result.class); + String tokenJson = "{\"success\":true,\"code\":200,\"message\":\"鎴愬姛\",\"data\":{\"ctoken\":\"ZmYxZTgyN2QxZTYyNDMxMDhjZjgzNDNiNDZiN2RjMDVAYTc3ZmFlOGE5ZGM0OGQ1Y2ZmODY4ZTFmNWYwZTEzM2E=\",\"userInfo\":{\"loginLogId\":\"1ab1675c3632428a84dc0ebe579cd66f\",\"phoneNumber\":\"\",\"displayName\":\"鏃剁┖涓�寮犲浘\",\"userMail\":\"\",\"departLevel\":\"5-1\",\"id\":\"ff1e827d1e6243108cf8343b46b7dc05\",\"userID\":\"shikong001\",\"uniqueID\":\"\",\"departName\":\"姹借溅鍜屾櫤鑳藉埗閫犱骇涓氫笓鐝璡"},\"expires\":3600,\"roles\":[]}}"; + Result rsToken = JSON.parseObject(tokenJson, Result.class); // TokenResult tr = JSON.parseObject(rs.getData().toJSONString(), TokenResult.class) - TokenResult tr = JSONObject.parseObject(rs.getData(), TokenResult.class); + TokenResult tr = JSONObject.parseObject(rsToken.getData(), TokenResult.class); + String token = tr.getCtoken(); - int len = json.length(); + String entJson = "{\"success\":true,\"code\":200,\"message\":\"鎴愬姛\",\"data\":{\"showCount\":2,\"totalPage\":30,\"totalResult\":59,\"currentPage\":2,\"currentResult\":2,\"entityOrField\":true,\"pd\":{\"ctoken\":\"ZmYxZTgyN2QxZTYyNDMxMDhjZjgzNDNiNDZiN2RjMDVAYTc3ZmFlOGE5ZGM0OGQ1Y2ZmODY4ZTFmNWYwZTEzM2E=\",\"showCount\":\"2\",\"qylabel\":\"寮�涓歕",\"buildDate_startdate\":\"2023-06-29\",\"currentPage\":\"2\",\"list\":[{\"entName\":\"鐓ょ閫氬畨锛堝寳浜級鏅烘帶绉戞妧鏈夐檺鍏徃\",\"fingerId\":\"649d7f468429fa3468856bc0\",\"regCapital\":\"4500\",\"regCapitalCNY\":\"4500\",\"legalPerson\":\"闇嶄腑鍒歕",\"address\":\"鍖椾含甯傚寳浜粡娴庢妧鏈紑鍙戝尯锛堝ぇ鍏达級閲囪偛闀囪偛闅嗗ぇ琛�5鍙穃",\"buildDate\":\"2023-06-29\",\"entType\":\"1190-鍏朵粬鏈夐檺璐d换鍏徃\",\"industryCategory\":\"M-绉戝鐮旂┒鍜屾妧鏈湇鍔′笟\",\"businessScope\":\"涓�鑸」鐩細鎶�鏈湇鍔°�佹妧鏈紑鍙戙�佹妧鏈挩璇€�佹妧鏈氦娴併�佹妧鏈浆璁┿�佹妧鏈帹骞匡紱宸ョ▼鍜屾妧鏈爺绌跺拰璇曢獙鍙戝睍锛涘澶栨壙鍖呭伐绋嬶紱宸ョ▼绠$悊鏈嶅姟锛涚熆灞辨満姊伴攢鍞紱鐢垫皵璁惧閿�鍞紱浠櫒浠〃閿�鍞紱鐓ょ偔閿�鍞紙涓嶅湪鍖椾含鍦板尯寮�灞曞疄鐗╃叅鐨勪氦鏄撱�佸偍杩愭椿鍔級锛涜蒋浠跺紑鍙戯紱淇℃伅鍜ㄨ鏈嶅姟锛堜笉鍚鍙被淇℃伅鍜ㄨ鏈嶅姟锛夛紱骞垮憡鍒朵綔锛涘箍鍛婂彂甯冿紱骞垮憡璁捐銆佷唬鐞嗭紱浠櫒浠〃鍒堕�狅紱宸ヤ笟鑷姩鎺у埗绯荤粺瑁呯疆鍒堕�狅紱宸ヤ笟鑷姩鎺у埗绯荤粺瑁呯疆閿�鍞紱姘斿帇鍔ㄥ姏鏈烘鍙婂厓浠跺埗閫狅紱姘斿帇鍔ㄥ姏鏈烘鍙婂厓浠堕攢鍞紱鏈烘鐢垫皵璁惧鍒堕�狅紱鐗╄仈缃戣澶囧埗閫狅紱鏁版嵁澶勭悊鏈嶅姟銆傦紙闄や緷娉曢』缁忔壒鍑嗙殑椤圭洰澶栵紝鍑惀涓氭墽鐓т緷娉曡嚜涓诲紑灞曠粡钀ユ椿鍔級璁稿彲椤圭洰锛氬畨鍏ㄧ敓浜ф楠屾娴嬶紱寤虹瓚鏅鸿兘鍖栫郴缁熻璁★紱寤虹瓚鍔冲姟鍒嗗寘銆傦紙渚濇硶椤荤粡鎵瑰噯鐨勯」鐩紝缁忕浉鍏抽儴闂ㄦ壒鍑嗗悗鏂瑰彲寮�灞曠粡钀ユ椿鍔紝鍏蜂綋缁忚惀椤圭洰浠ョ浉鍏抽儴闂ㄦ壒鍑嗘枃浠舵垨璁稿彲璇佷欢涓哄噯锛夛紙涓嶅緱浠庝簨鍥藉鍜屾湰甯備骇涓氭斂绛栫姝㈠拰闄愬埗绫婚」鐩殑缁忚惀娲诲姩銆傦級\",\"qylabel\":\"寮�涓歕"},{\"entName\":\"鍖椾含鑽e崕鍒╅�氭枃鍖栦紶濯掓湁闄愬叕鍙竆",\"fingerId\":\"649d7f468429fa3468856bc1\",\"regCapital\":\"50\",\"regCapitalCNY\":\"50\",\"legalPerson\":\"琚侀潤\",\"address\":\"鍖椾含甯傚寳浜粡娴庢妧鏈紑鍙戝尯鑽e崕鍗楄矾2鍙烽櫌2鍙锋ゼ5灞�509-1\",\"buildDate\":\"2023-06-29\",\"entType\":\"1130-鏈夐檺璐d换鍏徃(鑷劧浜烘姇璧勬垨鎺ц偂)\",\"industryCategory\":\"R-鏂囧寲銆佷綋鑲插拰濞变箰涓歕",\"businessScope\":\"涓�鑸」鐩細缁勭粐鏂囧寲鑹烘湳浜ゆ祦娲诲姩锛涗細璁強灞曡鏈嶅姟锛涘浘鏂囪璁″埗浣滐紱鏁板瓧鍐呭鍒朵綔鏈嶅姟锛堜笉鍚嚭鐗堝彂琛岋級锛涗俊鎭挩璇㈡湇鍔★紙涓嶅惈璁稿彲绫讳俊鎭挩璇㈡湇鍔★級锛涘競鍦鸿皟鏌ワ紙涓嶅惈娑夊璋冩煡锛夛紱骞垮憡鍒朵綔锛涘箍鍛婅璁°�佷唬鐞嗭紱骞垮憡鍙戝竷锛涘钩闈㈣璁★紱绀句細缁忔祹鍜ㄨ鏈嶅姟锛涘競鍦鸿惀閿�绛栧垝锛涘挩璇㈢瓥鍒掓湇鍔★紱浼佷笟褰㈣薄绛栧垝銆傦紙闄や緷娉曢』缁忔壒鍑嗙殑椤圭洰澶栵紝鍑惀涓氭墽鐓т緷娉曡嚜涓诲紑灞曠粡钀ユ椿鍔級锛堜笉寰椾粠浜嬪浗瀹跺拰鏈競浜т笟鏀跨瓥绂佹鍜岄檺鍒剁被椤圭洰鐨勭粡钀ユ椿鍔ㄣ�傦級\",\"qylabel\":\"寮�涓歕"}],\"buildDate_enddate\":\"2023-06-30\"}}}"; + Result rsEnt = JSON.parseObject(entJson, Result.class); + EntResult er = JSONObject.parseObject(rsEnt.getData(), EntResult.class); + List<EntEntity> entList = er.getPd().getList(); + + int len = tokenJson.length(); } } diff --git a/src/main/java/com/smartearth/poiexcel/controller/EntController.java b/src/main/java/com/smartearth/poiexcel/controller/EntController.java index 908ae80..debf3ae 100644 --- a/src/main/java/com/smartearth/poiexcel/controller/EntController.java +++ b/src/main/java/com/smartearth/poiexcel/controller/EntController.java @@ -1,8 +1,6 @@ package com.smartearth.poiexcel.controller; import com.smartearth.poiexcel.entity.ResponseMsg; -import com.smartearth.poiexcel.entity.Result; -import com.smartearth.poiexcel.entity.TokenResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; diff --git a/src/main/java/com/smartearth/poiexcel/entity/EntResult.java b/src/main/java/com/smartearth/poiexcel/entity/EntResult.java new file mode 100644 index 0000000..a86ff8d --- /dev/null +++ b/src/main/java/com/smartearth/poiexcel/entity/EntResult.java @@ -0,0 +1,162 @@ +package com.smartearth.poiexcel.entity; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * 浼佷笟缁撴灉绫� + * @author WWW + */ +public class EntResult implements Serializable { + private static final long serialVersionUID = -8624235184539814993L; + + private Integer showCount; + + private Integer totalPage; + + private Integer totalResult; + + private Integer currentPage; + + private Integer currentResult; + + private Boolean entityOrField; + + private PageData pd; + + public EntResult() { + } + + public Integer getShowCount() { + return showCount; + } + + public void setShowCount(Integer showCount) { + this.showCount = showCount; + } + + public Integer getTotalPage() { + return totalPage; + } + + public void setTotalPage(Integer totalPage) { + this.totalPage = totalPage; + } + + public Integer getTotalResult() { + return totalResult; + } + + public void setTotalResult(Integer totalResult) { + this.totalResult = totalResult; + } + + public Integer getCurrentPage() { + return currentPage; + } + + public void setCurrentPage(Integer currentPage) { + this.currentPage = currentPage; + } + + public Integer getCurrentResult() { + return currentResult; + } + + public void setCurrentResult(Integer currentResult) { + this.currentResult = currentResult; + } + + public Boolean getEntityOrField() { + return entityOrField; + } + + public void setEntityOrField(Boolean entityOrField) { + this.entityOrField = entityOrField; + } + + public PageData getPd() { + return pd; + } + + public void setPd(PageData pd) { + this.pd = pd; + } + + public static class PageData { + private String ctoken; + + private Integer showCount; + + private String qylabel; + + private String buildDate_startdate; + + private String buildDate_enddate; + + private Integer currentPage; + + private List<EntEntity> list; + + public PageData() { + list = new ArrayList<>(); + } + + public String getCtoken() { + return ctoken; + } + + public void setCtoken(String ctoken) { + this.ctoken = ctoken; + } + + public Integer getShowCount() { + return showCount; + } + + public void setShowCount(Integer showCount) { + this.showCount = showCount; + } + + public String getQylabel() { + return qylabel; + } + + public void setQylabel(String qylabel) { + this.qylabel = qylabel; + } + + public String getBuildDate_startdate() { + return buildDate_startdate; + } + + public void setBuildDate_startdate(String buildDate_startdate) { + this.buildDate_startdate = buildDate_startdate; + } + + public String getBuildDate_enddate() { + return buildDate_enddate; + } + + public void setBuildDate_enddate(String buildDate_enddate) { + this.buildDate_enddate = buildDate_enddate; + } + + public Integer getCurrentPage() { + return currentPage; + } + + public void setCurrentPage(Integer currentPage) { + this.currentPage = currentPage; + } + + public List<EntEntity> getList() { + return list; + } + + public void setList(List<EntEntity> list) { + this.list = list; + } + } +} -- Gitblit v1.9.3