baomidou/mybatis-plus · error · MybatisPlusException
非法SQL,where条件中不能使用【!=】关键字,错误!=信息:{}
Error message
非法SQL,where条件中不能使用【!=】关键字,错误!=信息:{} What it means
IllegalSQLInnerInterceptor from the jsqlparser-5.0 module: the WHERE expression (after unwrapping ParenthesedExpressionList) is a NotEqualsTo node, i.e. the SQL uses != / <>, which the interceptor's index-friendly policy forbids. Same rule as the 4.9 module, on the 5.x AST.
Source
Thrown at mybatis-plus-jsqlparser-support/mybatis-plus-jsqlparser-5.0/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/IllegalSQLInnerInterceptor.java:178
}
/**
* 验证expression对象是不是 or、not等等
*
* @param expression ignore
*/
private void validExpression(Expression expression) {
while (expression instanceof ParenthesedExpressionList) {
ParenthesedExpressionList<Expression> parenthesis = (ParenthesedExpressionList) expression;
expression = parenthesis.get(0);
}
//where条件使用了 or 关键字
if (expression instanceof OrExpression) {
OrExpression orExpression = (OrExpression) expression;
throw new MybatisPlusException("非法SQL,where条件中不能使用【or】关键字,错误or信息:" + orExpression.toString());
} else if (expression instanceof NotEqualsTo) {
NotEqualsTo notEqualsTo = (NotEqualsTo) expression;
throw new MybatisPlusException("非法SQL,where条件中不能使用【!=】关键字,错误!=信息:" + notEqualsTo.toString());
} else if (expression instanceof BinaryExpression) {
BinaryExpression binaryExpression = (BinaryExpression) expression;
// TODO 升级 jsqlparser 后待实现
// if (binaryExpression.isNot()) {
// throw new MybatisPlusException("非法SQL,where条件中不能使用【not】关键字,错误not信息:" + binaryExpression.toString());
// }
if (binaryExpression.getLeftExpression() instanceof Function) {
Function function = (Function) binaryExpression.getLeftExpression();
throw new MybatisPlusException("非法SQL,where条件中不能使用数据库函数,错误函数信息:" + function.toString());
}
if (binaryExpression.getRightExpression() instanceof Subtraction) {
Subtraction subSelect = (Subtraction) binaryExpression.getRightExpression();
throw new MybatisPlusException("非法SQL,where条件中不能使用子查询,错误子查询SQL信息:" + subSelect.toString());
}
} else if (expression instanceof InExpression) {
InExpression inExpression = (InExpression) expression;
if (inExpression.getRightExpression() instanceof Subtraction) {
Subtraction subSelect = (Subtraction) inExpression.getRightExpression();View on GitHub (pinned to bf67d90747)
Solutions
- Rewrite as a positive predicate: deleted != 1 becomes deleted = 0 or status IN (...).
- Use @InterceptorIgnore(illegalSql = "true") on the specific mapper method for an reviewed exception.
- Relax policy project-wide by removing the interceptor if != predicates are accepted.
Example fix
// before wrapper.ne(User::getDeleted, 1); // after wrapper.eq(User::getDeleted, 0);
Defensive patterns
Strategy: validation
Validate before calling
// CI guard: forbid .ne( / != / <> in mapped SQL before the interceptor ever runs
// git grep -nE "\.ne\\(|<>|!=" -- src/main/resources/mapper src/main/java && { echo 'policy: no != predicates'; exit 1; } Try / catch
try {
mapper.selectList(wrapper);
} catch (MybatisPlusException e) {
if (String.valueOf(e.getMessage()).contains("不能使用【!=】")) {
log.error("policy violation: use eq/in instead of !=: {}", e.getMessage());
}
} Prevention
- Encode soft-delete and status checks as positive predicates (eq/in) from the start.
- Add a CI grep or ArchUnit rule banning .ne() and <> usage.
- Onboard new developers with the interceptor policy so violations are caught in review, not at runtime.
When it happens
Trigger: Executing a query with a 'col != value' / 'col <> value' predicate — wrapper.ne(...) or hand-written SQL — while the 5.0 IllegalSQLInnerInterceptor is active.
Common situations: Soft-delete style filters (deleted != 1) written with .ne(); migrating code into a project where the interceptor was enabled, so previously-fine != predicates now throw.
Related errors
- 非法SQL,where条件中不能使用【or】关键字,错误or信息:{}
- 非法SQL,where条件中不能使用【!=】关键字,错误!=信息:{}
- 非法SQL,where条件中不能使用数据库函数,错误函数信息:{}
- 非法SQL,where条件中不能使用子查询,错误子查询SQL信息:{}
- 非法SQL,SQL未使用到索引, table:{}, columnName:{}
AI-assisted analysis of baomidou/mybatis-plus@bf67d90747 (2026-08-14).
Data as JSON: /api/errors/9e8af1e54da7ac36.
Report an issue: GitHub.