数据库中id属性为主键,不允许为空值
<select id="getUser"
resultType="com.hundsun.zdr.Stu">
SELECT * FROM Stu WHERE TRUE
<if test="id!=0">
and id = #{id}
</if>
<if test="name!=null">
and name like CONCAT('%',#{name},'%')
</if>
<if test="birthday!=null">
AND birthday like CONCAT('%',#{birthday},'%')
</if>
<if test="sex!=null">
AND sex like CONCAT(#{sex},'%')
</if>
<if test="address!=null">
AND address like CONCAT('%',#{address},'%')
</if>
<if test="teacher!=null">
AND teacher like CONCAT('%',#{teacher},'%')
</if>
</select>
<if test="id!=0">
and id = #{id}
</if>
如果写成这样
<if test="id!=null">
and id = #{id}
</if>
查询的时候保证id的值不能为空才能正常的查询到值
这个问题很困扰我