加入mybatis操作后输入查询条件查询不出结果,之前不使用可以根据条件查询出结果
我把查询条件限定为
message.setCommand("查看"); messageList = sqlSession.selectList("Message.queryMessageList",message);
通过log4j打印的日志信息是
[DEBUG] - [17:49:47.495]==> Preparing: SELECT idmessage,COMMAND,DESCRIPTION,CONTENT from MESSAGE WHERE COMMAND=? | (BaseJdbcLogger^debug:181) [DEBUG] - [17:49:47.522]==> Parameters: 查看(String) | (BaseJdbcLogger^debug:181) [DEBUG] - [17:49:47.535]<== Total: 0 | (BaseJdbcLogger^debug:181)
然后mybatis的数据操作配置是
<select id="queryMessageList" parameterType="com.imooc.bean.Message" resultMap="MessageResult"> SELECT idmessage,COMMAND,DESCRIPTION,CONTENT from MESSAGE <where> <if test="command !=null and !"".equals(command.trim())"> and COMMAND=#{command,jdbcType=VARCHAR}</if> <if test="description !=null and !"".equals(description.trim())"> and DESCRIPTION like '%'#{description,jdbcType=VARCHAR}'%'</if> </where> </select>
可以从log4j打印的结果看出没有查询出信息,这是怎么回事呢?
如果页面上不使用查询条件(command="查看" or description="精彩"),可以获得六条记录……