<select id="queryMessageList" parameterType="com.imooc.bean.Message" resultMap="MessageResult"> select ID,COMMAND,DESCRIPTION,CONTENT from MESSAGE <where> <if test="command != null and !"".equals(command.trim())"> and COMMAND=#{command} </if> <if test="description != null and !"".equals(description.trim())"> and DESCRIPTION like '%' #{description} '%' </if> </where> </select>
command 等于号改改成了 like + % 为什么就是查不到结果
DESCRIPTION 一直就可以啊 而且debug调试的时候都有值的
'%' _#{description}_ '%',这一段里面的_换成空格
可以啊,我试过能模糊查询指令
<select id="queryMessageList" parameterType="icoom.bean.Message"
resultMap="MessageResult">
select ID,COMMAND,DESCRIPTION,CONTENT FROM message where 1= 1
<if test="command != null and !"".equals(command.trim())">
and COMMAND like '%' #{command}
</if>
<if test="description != null and !"".equals(description.trim())">
and DESCRIPTION like '%' #{description}
</if>
</select>
改成这样command就查不到了,DESCRIPTION 还是可以查的
<select id="queryMessageList" parameterType="com.imooc.bean.Message" resultMap="MessageResult"> select ID,COMMAND,DESCRIPTION,CONTENT from MESSAGE <where> <if test="command != null and !"".equals(command.trim())"> and COMMAND like '%' #{command} '%' </if> <if test="description != null and !"".equals(description.trim())"> and DESCRIPTION like '%' #{description} '%' </if> </where> </select>