mybatis将字段名作为参数传入
需要注意的是在mybatis取字段时要用${}而不是#{},因为使用#{}会将传入的字段名预编译为?从而查不出数据,使用 ${}可以固定字段名直接使用字符串,
mapper代码
List<Student> selectAddOrRedo(@Param("fileType")String fileType, @Param("noneOrDisable")String noneOrDisable);```
XML代码
SELECT * FROM tb_student_detail
WHERE
<if test="noneOrDisable == 'none'">
(${fileType} = "0" OR #{fileType} = null)
</if>
<if test="noneOrDisable == 'disable'">
${fileType} = "-1"
</if>
AND
state = "0"
</select>