iBATIS - 使用总结
a.sqlMap的配置:
<sqlMapConfig>
<sqlMap resource="WEB-INF/configs/data.xml" />
<!--<sqlMap resource="WEB-INF/configs/addEmployee.xml" />-->
</sqlMapConfig>
b:如下文件叫data.xml
<sqlMap>
<typeAlias alias="employee" type="com.bean.Employee" />
<typeAlias alias="departMent" type="com.bean.Department" />
<resultMap id="employeeMap" column="emp_no" />
<result property="firName" column="first_name" />
<result property="lastName" column="last_name" />
<result property="phoneNum" column="phone_no" />
<result property="hireDate" column="hire_date" />
<result property="sex" column="sex" />
<result property="bithDate" column="birth_date" />
<result property="deptNum" column="dept_no" />
</resultMap>
<resultMap id="deptMap" column="dept_no" />
<result property="deptName" column="dept_name" />
<result property="manaName" column="manager_name" />
<result property="location" column="location" />
</resultMap>
<!--
<select id="employee" parameterparameterparameter
resultMap="employeeMap">
<![CDATA[
SELECT EMP.first_name,EMP.last_name,EMP.emp_no,EMP.phone_no,EMP.hire_date,EMP.sex,EMP.birth_date,EMP.dept_no FROM
t_employee EMP;
]]>
------------------------------------------------------
</select>
<!-- 利用hashmap来作为返回的结果 -->
<select id="getAllUser"
resultparameterparameterparameterparameterparameterClass="java.util.HashMap"
resultClass="java.lang.Long">
<![CDATA[
select distinct count(EMP.emp_no) from t_employee EMP
where EMP.emp_no = 20001
and a.update_dt >= date_format(#startDate#, '%Y-%m-%d')
and a.update_dt <= date_format(#endDate#, '%Y-%m-%d');
]]>
</select>
</sqlMap>