{"record":{"id":"9e8af1e54da7ac36","repo":"baomidou/mybatis-plus","slug":"sql-where-9e8af1","errorCode":null,"errorMessage":"非法SQL，where条件中不能使用【!=】关键字，错误!=信息：{}","messagePattern":"非法SQL，where条件中不能使用【!=】关键字，错误!=信息：(.+?)","errorType":"exception","errorClass":"MybatisPlusException","httpStatus":null,"severity":"error","filePath":"mybatis-plus-jsqlparser-support/mybatis-plus-jsqlparser-5.0/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/IllegalSQLInnerInterceptor.java","lineNumber":178,"sourceCode":"    }\n\n    /**\n     * 验证expression对象是不是 or、not等等\n     *\n     * @param expression ignore\n     */\n    private void validExpression(Expression expression) {\n        while (expression instanceof ParenthesedExpressionList) {\n            ParenthesedExpressionList<Expression> parenthesis = (ParenthesedExpressionList) expression;\n            expression = parenthesis.get(0);\n        }\n        //where条件使用了 or 关键字\n        if (expression instanceof OrExpression) {\n            OrExpression orExpression = (OrExpression) expression;\n            throw new MybatisPlusException(\"非法SQL，where条件中不能使用【or】关键字，错误or信息：\" + orExpression.toString());\n        } else if (expression instanceof NotEqualsTo) {\n            NotEqualsTo notEqualsTo = (NotEqualsTo) expression;\n            throw new MybatisPlusException(\"非法SQL，where条件中不能使用【!=】关键字，错误!=信息：\" + notEqualsTo.toString());\n        } else if (expression instanceof BinaryExpression) {\n            BinaryExpression binaryExpression = (BinaryExpression) expression;\n            // TODO 升级 jsqlparser 后待实现\n//            if (binaryExpression.isNot()) {\n//                throw new MybatisPlusException(\"非法SQL，where条件中不能使用【not】关键字，错误not信息：\" + binaryExpression.toString());\n//            }\n            if (binaryExpression.getLeftExpression() instanceof Function) {\n                Function function = (Function) binaryExpression.getLeftExpression();\n                throw new MybatisPlusException(\"非法SQL，where条件中不能使用数据库函数，错误函数信息：\" + function.toString());\n            }\n            if (binaryExpression.getRightExpression() instanceof Subtraction) {\n                Subtraction subSelect = (Subtraction) binaryExpression.getRightExpression();\n                throw new MybatisPlusException(\"非法SQL，where条件中不能使用子查询，错误子查询SQL信息：\" + subSelect.toString());\n            }\n        } else if (expression instanceof InExpression) {\n            InExpression inExpression = (InExpression) expression;\n            if (inExpression.getRightExpression() instanceof Subtraction) {\n                Subtraction subSelect = (Subtraction) inExpression.getRightExpression();","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/baomidou/mybatis-plus/blob/bf67d907478c724120bf76292da54abf9e73c2b3/mybatis-plus-jsqlparser-support/mybatis-plus-jsqlparser-5.0/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/IllegalSQLInnerInterceptor.java#L160-L196","documentation":"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.","triggerScenarios":"Executing a query with a 'col != value' / 'col <> value' predicate — wrapper.ne(...) or hand-written SQL — while the 5.0 IllegalSQLInnerInterceptor is active.","commonSituations":"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.","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."],"exampleFix":"// before\nwrapper.ne(User::getDeleted, 1);\n\n// after\nwrapper.eq(User::getDeleted, 0);","handlingStrategy":"validation","validationCode":"// CI guard: forbid .ne( / != / <> in mapped SQL before the interceptor ever runs\n// git grep -nE \"\\.ne\\\\(|<>|!=\" -- src/main/resources/mapper src/main/java && { echo 'policy: no != predicates'; exit 1; }","typeGuard":null,"tryCatchPattern":"try {\n    mapper.selectList(wrapper);\n} catch (MybatisPlusException e) {\n    if (String.valueOf(e.getMessage()).contains(\"不能使用【!=】\")) {\n        log.error(\"policy violation: use eq/in instead of !=: {}\", e.getMessage());\n    }\n}","preventionTips":["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."],"tags":["mybatis-plus","jsqlparser","sql-parsing","interceptor","policy"],"backgroundTag":null,"analyzedSha":"bf67d907478c724120bf76292da54abf9e73c2b3","analyzedAt":"2026-08-14T15:17:09.543Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}