在写业务的时候,经常会遇到对插入数据的某个字段进行重复性校验。为了规范书写,记录一下。
XXXMapper层
/**
* 检查部门名称是否重复
* @param department
* @return
*/
int checkNameExist(Department department);
XXXMapper.xml层
<select id="checkNameExist" resultType="java.lang.Integer">
SELECT count(depart_id)
FROM department
<where>
is_deleted = 0
<if test="departId !=null and departId !=''">
AND depart_id != #{departId}
</if>
AND depart_name = #{departName}
</where>
</select>