mybatis传单个参数,和<if>标签同时使用的问题
// Mapper.java EmerEvent selectByAlarmId(Integer alarmId); // Mapper.xml <select id="selectByAlarmId" resultMap="BaseResultMap" parameterType="java.lang.Integer"> select <include refid="Base_Column_List" /> from event <where> <if test="alarmId != null"> and alarm_id = #{alarmId,jdbcType=Integer} </if> </where> </select>
由于只传了一个参数:alarmId,配置文件中对应的sql里使用if标签,然后报错:
nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'alarmId' in 'class java.lang.Integer'
解决办法:
1.将mapper配置文件中的sql语句中的if判断去掉
<select id="selectByAlarmId" resultMap="BaseResultMap" parameterType="java.lang.Integer"> select <include refid="Base_Column_List" /> from event where alarm_id = #{alarmId,jdbcType=Integer} </select>
2.如果想要使用if标签,则将参数alarmId封装到对象或Map中即可