<select id="getNewsCount" parameterType="com.dxm.dto.NewsPageDto" resultType="Integer">
select count(*) from news
<where>
<if test="status!=null and status!='' ">
status=#{status}
</if>
</where>
</select>
select count(*) from news where status=? .
sql语句的参数值出现了丢失的情况
仔细分析是因为数据类型的原因
解答:
字段 status在表中是 int型而属性 status 在NewsPageDto 对象中是 String类型,故造成status值丢失,sql出错。
将实体的status属性改为与数据库字段status类型一致,因为是int类型,去掉sql中if 判断 status!='' 的 。
<select id="getNewsCount" parameterType="com.dxm.dto.NewsPageDto" resultType="Integer">
select count(*) from news
<where>
<if test="status!=null > status=#{status} </if>
</where>
</select>
注意:int 型数据 在sql 的if 判断中只需要判断 !=null 即可。