實體Entity轉化為map型別
問題:如何將實體entity轉化為map型別,並傳給陣列的方法,獲取其中的某個欄位
例如實體為nbcsgFile
@Autowired
private Test test:
Map entity = BeanUtils.describe(nbcsgFile);//nbcsgFile實體物件
nbcsgFile.setNbcsg01(test.getall(entity))//傳值給方法getall 建立一個Test類的物件,將nbcsgFile實體轉化為map傳遞給getall方法
在Test類中
String section = (String)entity.get(某欄位);
這樣section就為我們需要的實體中的某欄位。
附實際開發程式碼:
service對應層的傳遞程式碼 Map entity = BeanUtils.describe(nbcsgFile); nbcsgFile.setNbcsg01(this.oddNumberBasic.getAll(“nbcsg”,“nbcsg01”,entity,nbcsgFile));
對應oddNumberBasic=Test類下方法的程式碼 String section2 = (String)entity.get(returnTwoDan);//returnTwoDan為獲取的某欄位值 String section3 = (String)entity.get(returnThreeDan);//returnThreeDan為獲取的某欄位值 附returnTwoDan、returnThreeDan /**
-
getTwoDan 獲取預設表段2
-
*/ public String getTwoDan(String KeyTable )throws Exception{ this.KeyTable=KeyTable.concat("_file"); String sqlgetTwoDan=null; String returnTwoDan=null;
sqlgetTwoDan=“select nbcst05 from nbcst_file where nbcst11=?”; Map gettwo=jdbcDao.queryForMap(sqlgetTwoDan,this.KeyTable); if (sqlgetTwoDan!=null){ returnTwoDan=MapUtils.getString(gettwo,“nbcst05”); }else { throw new Exception(“段位2欄位空異常”); } return returnTwoDan; } /**
-
getThreeDan 獲取預設表段3
-
*/ public String getThreeDan(String KeyTable )throws Exception{ this.KeyTable=KeyTable.concat("_file"); String sqlgetThreeDan=null; String returnThreeDan=null;
sqlgetThreeDan=“select nbcst07 from nbcst_file where nbcst11=?”; Map gettwo=jdbcDao.queryForMap(sqlgetThreeDan,this.KeyTable); if (sqlgetThreeDan!=null){ returnThreeDan=MapUtils.getString(gettwo,“nbcst07”); }else { throw new Exception(“段位3欄位空異常”); } return returnThreeDan; } 以上程式碼都為實際開發程式碼,記錄原理。
面向開發需求,記錄學習之路♪(^∀^●)ノ