1. 程式人生 > 其它 >mybatis中傳多個不同型別的引數(以兩個引數為例)的實現?

mybatis中傳多個不同型別的引數(以兩個引數為例)的實現?

1、使用實體類物件包裝引數:

/* seviceImpl層 */
public
List<SysDept> getFaculty() { SysDept dept = new SysDept(); dept.setDeptType(2); dept.setStatus("0"); return deptMapper.selectDeptList(dept); }

/*.xml層對應 */
<select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult">
<include refid="selectDeptVo"/>
where d.del_flag = '0'
<if test="status != null and status != ''">
AND status = #{status}
</if>
<if test="deptType != null and deptType != 0 ">
AND dept_type = #{deptType}
</if>
</select>

2、使用@Param註解

/* mapper層對應介面 */
List<SysDept> queryDeptForMajorOrGrade(@Param("deptId") Long deptId, @Param("deptType") String deptType);

/* .xml層對應 (不用寫引數型別 parameterType的值 )*/
<select id="queryDeptForMajorOrGrade" resultMap="SysDeptResult">
select d.dept_id, d.dept_name from sys_dept d where d.del_flag = '0' and d.status = '0' and find_in_set(#{deptId}, ancestors) and dept_type = #{deptType}
</select>

3、其他。。。 集合等