错误的原因是因为查询语句使用错误。
比如一个用户表的属性有编号Integer id、用户名String username和密码String password。
当要根据编号id查询user时,id是int类型装箱后的数据类型,本质是数字,可以直接使用查询语句select * from 表名 where id=${id}
。
当要查询用户名username查询user时,username是String类型的数据,所以,应加单引号select * from 表名 where username=${username}
。