全查詢可以查出,條件查詢不到,疑惑???幫忙看下哪有問(wèn)題。。。
看之前有童鞋出了這問(wèn)題,然后說(shuō)在Dao中trim()了,我試了,沒效果。代碼如下:
Dao層:
//獲取message表中數(shù)據(jù)
public List<Message> messagelist(String command,String description){
List<Message> messagelist = null;
//調(diào)用Dao操作方法
//messagelist = this.dbaccess(command,description);
//調(diào)用Mybatis方式操作方法
SqlSession sqlSession = null;
Message message = new Message();
//檢索數(shù)據(jù)處理
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{
//關(guān)閉數(shù)據(jù)庫(kù)連接會(huì)話
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
新建數(shù)據(jù)庫(kù)表的時(shí)候默認(rèn)是GBK的編碼,自己改一下UTF-8就行了UTF-8,
mybatis也設(shè)置了默認(rèn)的編碼是UTF-8吧,
2016-05-25
我也出現(xiàn)了這個(gè)情況,eclipse文件編碼和數(shù)據(jù)庫(kù)編碼都確認(rèn)過(guò)是utf-8,最后還是在url追加的編碼,難道以后都要這樣嗎?
2016-04-28
我搞了幾個(gè)小時(shí)快崩潰了
我特意回來(lái)解答一下問(wèn)題 :
url地址后面添加?useUnicode=true&characterEncoding=UTF-8,問(wèn)題就可以解決了
mysql默認(rèn)是GBK編碼的 我們輸入的字符會(huì)轉(zhuǎn)化為UTF-8 所以亂碼了 匹配不上
2015-09-25
我轉(zhuǎn)碼了啊,還是查不出。條件查詢查不出,其他都沒事,也沒異常。
2015-09-03
問(wèn)題解決了,和jdbc時(shí)候一樣,需要設(shè)置字符集。。。一個(gè)坑栽了兩次,醉了。。。