select count(*) from user where username LIKE '%ss%'
uj5u.com熱心網友回復:
你好是這樣的,那個問題我已經知道是等號的問題,但是現在我碰到一個類似的問題,我在資料表用select Count(*) from user where user.sex=1 and user.username like '%小明%'這個查詢陳述句查詢得到的值是3,然后我用mybatis做一個測驗得到的卻是一個null;
這是<select id="findCount" parameterType="User_UserCustom_vo" resultType="userCustom">
select Count(*) from user where user.sex=#{userCustom.sex} and user.username like '%${userCustom.username}%'
</select>的查詢陳述句設定注入的值是1和小明,為什么我在資料表查詢可以得到值,而在mybatis查詢的到卻是null
這是測驗的方法
@Test
public void testFindCount() throws Exception
{
SqlSession session =sqlSessionFactory.openSession();
UserMapper userMapper =session.getMapper(UserMapper.class);
UserCustom userCustom = new UserCustom();
userCustom.setSex("1");
userCustom.setUsername("小明");
User_UserCustom_vo user_UserCustom_vo = new User_UserCustom_vo();
user_UserCustom_vo.setUserCustom(userCustom);
int i =userMapper.findCount(user_UserCustom_vo);
System.err.println(i);
}
這是User_UserCustom_vo 類
public class User_UserCustom_vo {
private List<Integer> ids;
public List<Integer> getIds() {
return ids;
}
public void setIds(List<Integer> ids) {
this.ids = ids;
}
private UserCustom userCustom;
public UserCustom getUserCustom() {
return userCustom;
}
public void setUserCustom(UserCustom userCustom) {
this.userCustom = userCustom;
}
}
uj5u.com熱心網友回復:
這是控制臺的資訊:DEBUG [main] - Created connection 1891254926.
DEBUG [main] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.Connection@70ba428e]
DEBUG [main] - ==> Preparing: select Count(*) from user where user.sex=? and user.username like '%小明%'
DEBUG [main] - ==> Parameters: 1(String)
DEBUG [main] - <== Total: 1
null
uj5u.com熱心網友回復:
LIKE
uj5u.com熱心網友回復:
like
instr locate
uj5u.com熱心網友回復:
把等號換成like
uj5u.com熱心網友回復:
把等號換成like
等號的我已經知道了。
uj5u.com熱心網友回復:
把等號換成like
等號的我已經知道了。
我想知道的是關于前面的問題
uj5u.com熱心網友回復:
select Count(*) from user where user.sex=#{userCustom.sex}
這里的#號什么意思,搞錯了吧 $吧,如果是這個問題,你要仔細了
like '%${userCustom.username}%'
uj5u.com熱心網友回復:
=號換like...
uj5u.com熱心網友回復:
select Count(*) from user where user.sex=#{userCustom.sex}
這里的#號什么意思,搞錯了吧 $吧,如果是這個問題,你要仔細了
like '%${userCustom.username}%'
# 號是預編譯的哦
$是拼SQL的。
uj5u.com熱心網友回復:
select Count(*) from user where user.sex=#{userCustom.sex}
這里的#號什么意思,搞錯了吧 $吧,如果是這個問題,你要仔細了
like '%${userCustom.username}%'
**桔妹導讀:**深耕人工智能領域,致力于探索AI讓出行更美好的滴滴AI Labs再次斬獲國際大獎,這次獲獎的專案是什么呢?一起來看看詳細報道吧! 近日,由國際計算語言學協會ACL(The Association for Computational Linguistics)舉辦的世界最具影響力的機器 ......
我們經常在資料庫中使用 LIKE 運算子來完成對資料的模糊搜索,LIKE 運算子用于在 WHERE 子句中搜索列中的指定模式。 如果需要查找客戶表中所有姓氏是“張”的資料,可以使用下面的 SQL 陳述句: SELECT * FROM Customer WHERE Name LIKE '張%' 如果需要 ......
關于MySQL的二進制日志(binlog),我們都知道二進制日志(binlog)非常重要,尤其當你需要point to point災難恢復的時侯,所以我們要對其進行備份。關于二進制日志(binlog)的備份,可以基于flush logs方式先切換binlog,然后拷貝&壓縮到到遠程服務器或本地服務器 ......