List物件集合的遍歷、物件賦值和向前臺傳遞
在前幾天的編程程序中,發現前臺需要的資料不完整,從資料庫查出來的欄位不夠,如果再多表聯查或者左聯會有我不想要的重復資料,而且會使SQL更加復雜,不利于維護,所有我決定用私有方法單獨查出相應欄位,然后通過增強for給每一個物件賦值,這樣免除了多余條,也給前臺傳遞了完整的資料,
// 根據entName:企業名稱,structureCode:登錄人部門代碼 roleCodes:權限代碼 查詢待審查串列部分欄位
DataListByPageDTO<SafetyDeptAuditDTO> list = safetyDeptAuditDao.querySafetyDeptAuditList(entName, structureCode, roleCodes, page, rows);
//創建一個新SafetyDeptAuditDTO集合用來存放處理后的物件
List<SafetyDeptAuditDTO> newlist = new ArrayList<>();
//增強for回圈 遍歷list
for(SafetyDeptAuditDTO safetyDeptAuditDTO : list.getDataList()){
//獲取對應字典節點值
CodeForEntDTO codeForEntDTO = safetyDeptAuditDao.enttypeToContent(safetyDeptAuditDTO.getEnttype());
//設定企業型別,取到節點值則置值,無節點值置空
if(codeForEntDTO!=null) {
//設定企業型別
safetyDeptAuditDTO.setEnttype(codeForEntDTO.getContent());
}else {
//設定企業型別空
safetyDeptAuditDTO.setEnttype(" ");
}
//將處理好的物件放入新集合
newlist.add(safetyDeptAuditDTO);
}
私有方法,獲取對應企業型別
public CodeForEntDTO enttypeToContent(String enttype){
// 查詢sql
String sql = "select content from gs_qylx where code=:enttype ";
// 查詢條件map
Map<String, Object> queryMap = new HashMap<>(2);
// 市場主體標識
queryMap.put("enttype", enttype);
// 中文欄位資訊
return basicDao.getByMap(sql, queryMap, CodeForEntDTO.class);
}
SQL
// 組裝查詢SQL頭陳述句
StringBuilder querySql = new StringBuilder(" select t1.id,t1.pripid,t1.openo,t2.entname,t2.enttype,t2.dom ");
// 組裝統計SQL頭陳述句
StringBuilder countSql = new StringBuilder(" select count(1) ");
// 組裝表名陳述句 公司企業登記安全審查流程表,公司企業登記流程表
StringBuilder tableSql = new StringBuilder(" from gs_qydj_aqsc_lc t1,gs_qydj_lc t2 ");
// 定義一個where查詢sql的字串 狀態為1的待審查
StringBuilder whereSql = new StringBuilder(" where t2.pripid=t1.pripid and t1.status='1' ");
這樣的話,我無需因為一個欄位繼續聯查第三張表,前臺需要的所有欄位都放在物件內傳遞了,同時如果后期要對前臺增加欄位或其他操作,在for內做相應賦值即可,
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/244347.html
標籤:其他
上一篇:必知必會的MySQL基礎知識
下一篇:資料庫系統(四)——觸發器
