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