全查询可以查出,条件查询不到,疑惑???帮忙看下哪有问题。。。
看之前有童鞋出了这问题,然后说在Dao中trim()了,我试了,没效果。代码如下:
Dao层:
//获取message表中数据
public List<Message> messagelist(String command,String description){
List<Message> messagelist = null;
//调用Dao操作方法
//messagelist = this.dbaccess(command,description);
//调用Mybatis方式操作方法
SqlSession sqlSession = null;
Message message = new Message();
//检索数据处理
if(command !=null&&!"".equals(command.trim())){
message.setCommand(command.trim());
}
if(description !=null&&!"".equals(description.trim())){
message.setDescription(description.trim());
}
try {
//获取sqlSession
sqlSession = this.dbaccess.mybatis();
//查询messagelist
messagelist = sqlSession.selectList("Message.messagelist",message);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
//关闭数据库连接会话
if(sqlSession != null){
sqlSession.close();
}
}
mappersql.xml配置文件:
<select id="messagelist" parameterType="blue.java.model.Message" resultMap="MessageResult">
select id,command,description,content from message where 1=1
<if test="command != null ">
and command = #{command}
</if>
<if test="description != null">
and description like '%' #{description} '%'
</if>
</select>
日志打印如下:
DEBUG [http-8080-2] - Opening JDBC Connection
DEBUG [http-8080-2] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@1dc696e]
DEBUG [http-8080-2] - ==> Preparing: select id,command,description,content from message where 1=1 and command = ?
DEBUG [http-8080-2] - ==> Parameters: 查看(String)
DEBUG [http-8080-2] - <== Total: 0
DEBUG [http-8080-2] - Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@1dc696e]
DEBUG [http-8080-2] - Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@1dc696e]