我在navicat中如题的sql语句查询时却得到一个0,但是我的数据表里面有多条username是ss的记录,如果用select count(*) from user where username='s'这条语句返回的就是10,为什么得到的是0,有人懂吗
解决方案 »
- 请大家谈谈近义词数据表的设计方案
- 急求帮忙 loongson下安装lamp
- 有记录则update,没有则insert
- PHP输入Mysql中文乱码
- 我想指定mysql的列值默认为空字符串
- 版主解释下interval这个函数还有 PY为S的username有很多 你是如何确定字符边界的
- 关于timestamp为什么总是自动更新
- 把表放进多数据库还是放进一个数据库好?
- 求助!各位高手,用DELPHI7的ADOQUERY查询MYSQL数据厍时出现class eacessviocation whit message access violation at address 100072 in m
- 求一分组结果
- 请问下kettle与syncnavigator那个同步数据好用呀
- 1064)您的SQL语法中有错误; 请检查与您的MySQL服务器版本对应的手册,以获取在...
----可能的原因是:等号 (=)问题 。
通配符的意思是“像”,不精确,应该用 like,不能用表示严格的等号。试试这个:select count(*) from user where username LIKE '%ss%'
这是<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;
}
}
这是<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;
}
}
这是控制台的信息: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
instr locate
这里的#号什么意思,搞错了吧 $吧,如果是这个问题,你要仔细了
like '%${userCustom.username}%'
# 号是预编译的哦
$是拼SQL的。
# 号是预编译的哦
$是拼SQL的。
没搞过mybatis ,能输出mybatis执行的语句吗,输出执行的语句贴出出来看
条件里面的等于号后面 单引号里面的字符串,系统识别为某一个值,user 表不存在,所以返回0条,等于号改为 like 代表模糊查询;