(一)查詢操作 //Action層:類: Hibernate映射:A--->A.hbm.xml List stList = new ArrayList(); stList .add("N"); stList .add(""); int snId = Integer.parseInt("6"); // ServiceConstants.SN_ID_MXZ="6" List snIdList = new ArrayList(); snIdList.add(snId); List aList = mxzerService.getA(stList , snIdList); if(!CollectionUtil.isEmpty(aList )){ // 通過工具包處理List對象 for(A a: aList ){ // ....具體其他操作 } } 工具類: public final class CollectionUtil { public static boolean isEmpty(Collection list){ if(list==null || list.isEmpty()){ return true; }else{ return false; } } } // Service + Dao層: @Override public List getA(List stList, List snIdList) { String hql =" from A c where c.statusCode in (:stList) and c.snId in (:snIdList)"; Session session = super.getSession(); Query query = session.createQuery(hql.toString()); query.setParameterList("stList", stList); query.setParameterList("snIdList", snIdList); //query.setMaxResults(300);// 如限制查詢結果的數量,可加該語句;一次查詢處理多少數據 return query.list(); } (二)更新操作 // Action層: List updateAList = new ArrayList(); A a = new A(); updateAList .add(a); mxzerService.updateA(updateAList); updateAList.clear(); // 清理一次 Service + Dao層: @Override public void updateA(List aList) throws Exception { mxzerDao.updateA(aList); } dao層: public class aImpl extends BaseDao implements IADao{} @Override public void updateA(List aList) throws Exception { super.saveOrUpdateByBatch(aList, 500); //一次要更新多少條數據 } (三)刪除操作 (四)新增操作