本文主要是介绍Mybatisplus Error querying database.Cause: java.sql.SQLException: Operand should contain 1 column(s),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Mybatis-plus Error querying database. Cause: java.sql.SQLException: Operand should contain 1 column(s)
/*** QueryWrapperSelect 实现子查询*/
@Test
public void QueryWrapperSelectSon(){//查询id小于等于100的用户信息QueryWrapper<User> queryWrapper = new QueryWrapper<>();
// queryWrapper.inSql("id", "select id from user where id <= 100");queryWrapper.inSql("username", "select * from user where username like '%金%' AND is_deleted=0");List<User> list = userMapper.selectList(queryWrapper);list.forEach(System.out::println);
}
在 Mybatis-Plus 实战项目中 通过 QueryWrapper 构造器实现子查询用户信息的时候报如下错误
Error querying database. Cause: java.sql.SQLException: Operand should contain 1 column(s)
org.springframework.jdbc.BadSqlGrammarException:
### Error querying database. Cause: java.sql.SQLException: Operand should contain 1 column(s)
### The error may exist in com/example/mybatisplus/mapper/UserMapper.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT id AS uid,username AS name,age,email,create_time,update_time,is_deleted FROM user WHERE is_deleted=0 AND (id IN (select * from user where id <= 100))
### Cause: java.sql.SQLException: Operand should contain 1 column(s)
; bad SQL grammar []; nested exception is java.sql.SQLException: Operand should contain 1 column(s)
报错原因:
select * from user where username like ‘%金%’ AND is_deleted=0 不能为 * ,而必须是数据库表中的某个字段才行
解决方法: 将 * 换成表中具体字段名,比如:username或id等等,即可解决报错问题
如上可查询到用户全部信息
这篇关于Mybatisplus Error querying database.Cause: java.sql.SQLException: Operand should contain 1 column(s)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!