Spring _MyBatis _etc

JoMinJun·2021년 4월 8일
0

받는 parameter 값 에 따라 유동적으로 선택하여 사용 가능

예1>

//interface dao
int getEmpCount();
int getEmpCount(int deptid);
//Mapper.xml
<select id = "getEmpCount" parameterType="int" resultType="int">
	SELECT COUNT(*) FROM employees
	<if test = "deptid != null">
		where department_id = #{deptid}
	</if>
</select>

예2>

//interface dao
List<EemployeeVO> getEemList();
EemployeeVO getEmplist(int empId);
//Mapper.xml
<select id = "getEemList"  parameterType="int" resultMap="empMap">
	SELECT * FROM EMPLOYEES
	<if test = "empid != null">
		WHERE employee_id = #{empid}
	</if>
</select>

기타 delete , update

//interface dao
void deleteEmp(int empId, String email);
void updateEmp(EemployeeVO emp);
   
//Mapper.xml
<delete id = "deleteEmp">
	DELETE FROM employees
	where employee_id=#{empid} AND email=#{email}
</delete>

<update id = "updateEmp" parameterType="com.spring.myapp.hr.vo.EemployeeVO">
</update>

	update employees
	set first_name=#{firstName}, last_name=#{lastName}, email=#{email},
	phone_number=#{phoneNumber} , hire_date=#{hireDate}, job_id=#{jobId}
	salary=#{salary}, commission_pct=#{commissionPct}, manager_id=#{mangerId}
	department_id=#{departmentId} where employee_id=#{employeeId};
profile
기술정리

0개의 댓글