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、其他。。。 集合等

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM