全查詢可以查出,條件查詢不到,疑惑???幫忙看下哪有問題。。。
看之前有童鞋出了這問題,然后說在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]
2016-06-29
新建數據庫表的時候默認是GBK的編碼,自己改一下UTF-8就行了UTF-8,
mybatis也設置了默認的編碼是UTF-8吧,
2016-05-25
我也出現了這個情況,eclipse文件編碼和數據庫編碼都確認過是utf-8,最后還是在url追加的編碼,難道以后都要這樣嗎?
2016-04-28
我搞了幾個小時快崩潰了
我特意回來解答一下問題 :
url地址后面添加?useUnicode=true&characterEncoding=UTF-8,問題就可以解決了
mysql默認是GBK編碼的 我們輸入的字符會轉化為UTF-8 所以亂碼了 匹配不上
2015-09-25
我轉碼了啊,還是查不出。條件查詢查不出,其他都沒事,也沒異常。
2015-09-03
問題解決了,和jdbc時候一樣,需要設置字符集。。。一個坑栽了兩次,醉了。。。