Monday 24 September 2012

IBATIS 2 SQL Map : Contoh hantar lebih 1 parameter gunakan java.util.Map


Contoh kita ada function dalam DAO IMPL:
public List<StaffSupervise> getExtSuperviseList(String staffId, String superviseCategory, String communityServiceType)
{
Map<String,String> paramMap = new HashMap<String, String>();
paramMap.put("p_staff_id", staffId);
paramMap.put("p_supervise_category", superviseCategory);
paramMap.put("p_comm_srvc_type", communityServiceType);

try{
@SuppressWarnings("unchecked")
List<StaffSupervise> list = this.getSqlMapClientTemplate().queryForList("STAFF_SUPERVISE.getStaffExtSuperv", paramMap);
return list;
} catch (Exception e){
e.printStackTrace();
return new ArrayList<StaffSupervise>();
}
}

Utk SQL Mapping pula 
(since structure CV-Online dgn APR berbeza sikit, abaikan perbezaan naming mapping.)

  <select id="STAFF_SUPERVISE.getStaffExternalSuperviseByCategoryAndSrvcType" resultMap="StaffSuperviseResultMap_3" parameterClass="java.util.Map" >
select ss.*,
om_name institution_desc, ql_desc level_desc, null duration_month
from staff_supervise ss, organization_main, qualification_level
where ss_institution = om_seq(+)
and ss_supervise_level = ql_code(+)
and ss_supervise_category = #p_supervise_category#
and ss_supervise_type = #p_comm_srvc_type#
and ss_staff_id = #p_staff_id#
  </select>

Dev info:
Code = APR, CV-Online
Framework = SPRING 2.5.6, IBATIS 2

No comments: