Spring _MyBatis _resultMap

쿼리문 자체에서 AS 를 이용해 컬럼명 AS 필드명 과 같이 이름을 일치시키는 방법

<select id = "getEmpList" resultType="com.spring.myapp.hr.vo.EemployeeVO">
	
	EMPLOYEE_ID as employeeId,
	FIRST_NAME as firstName,
    	LAST_NAME as lastName,
    	EMAIL as email,
    	PHONE_NUMBER as phoneNumber,
    	HIRE_DATE as hireDate,
	JOB_ID as jobId,
    	SALARY as salary,
    	COMMISSION_PCT as commissionPct,
    	MANAGER_ID as mangerId,
    	DEPARTMENT_ID as departmentId
	FROM EMPLOYEES

</select>

xml 파일 내부에서 resultMap 태그 사용

	<resultMap id = "empMap" type = "com.spring.myapp.hr.vo.EemployeeVO">
	<result column="EMPLOYEE_ID" property="employeeId"/>
	<result column="FIRST_NAME" property="firstName"/>
	<result column="LAST_NAME" property="lastName"/>
	<result column="EMAIL" property="email"/>
	<result column="PHONE_NUMBER" property="phoneNumber"/>
	<result column="HIRE_DATE" property="hireDate"/>
	<result column="JOB_ID" property="jobId"/>
	<result column="SALARY" property="salary"/>
	<result column="COMMISSION_PCT" property="commissionPct"/>
	<result column="MANAGER_ID" property="mangerId"/>
	<result column="DEPARTMENT_ID" property="departmentId"/>
	</resultMap>
<select id = "getEmpList" resultMap="empMap">

	SELECT * FROM EMPLOYEES
	<if test = "empid != null">
		WHERE employee_id = #{empid}
	</if>
</select>

좋은 웹페이지 즐겨찾기