跳到正文
Code Review

← 官方规则来源

Mapper / DAO XML · 官方规则原文

OpenCodeReview v1.13.8 · 4236c871 · Apache-2.0。保留固定版本英文原文;item 编号表示原文件中的检查项顺序。实际扫描以当前规则开关和扫描快照为准。

查看当前规则与开关 → · 下载原始 Markdown

版本与文件信息

提交:4236c871fe8130aa840a2a1c0922f469e87e0416

源码路径:internal/config/rules/rule_docs/mapper_dao_xml.md

SHA-256:8ff3a60e38e44986f82cba70cbbe7782ed4ea294486048336a14d173cf92678e

Apache-2.0 许可证 · 基线说明

Obvious Spelling Error Detection

  • Spelling errors in SQL keywords
  • Spelling mismatches between mapper interface method names and XML id attributes
  • Spelling errors in attribute names within dynamic SQL tags (e.g., field names in test conditions)

SQL Logic Error Detection

  • Condition Errors: Misuse of logical operators in WHERE conditions (AND/OR confusion)
  • JOIN Condition Errors: Incorrect fields used in join conditions or missing required join conditions
  • Dynamic SQL Logic Errors: Incorrect <if test=""> condition evaluation, such as null check errors or type check errors
  • SQL Syntax Errors: Obvious syntax errors such as missing commas or unmatched parentheses

Critical Performance Issues

  • Full Table Scan Risk: Missing WHERE conditions
  • Large Query Without Pagination: Queries that may return large datasets without using LIMIT or pagination
  • Repeated Subqueries: The same subquery used in multiple places; recommend extracting to a temporary table or optimizing SQL structure

SQL Injection Security Risk Detection

Real security risks that should be reported:

  • Direct String Concatenation: Using ${} to concatenate user input parameters into SQL statements poses SQL injection risks
  • LIKE Query Concatenation: Directly concatenating LIKE conditions instead of using safe parameter binding

Cases that should NOT be reported:

  • Proper Use of #{} Parameter Binding: MyBatis automatically escapes parameters, ensuring security
  • Static SQL Statements: Fixed SQL statements that do not involve dynamic parameters

Review Principles:

  • Focus on critical issues that may cause data corruption, performance problems, or security risks
  • Consider the actual execution efficiency of SQL statements and their impact on database performance
  • Prioritize identifying critical issues that could cause production failures
  • Exercise caution when context is unclear: when the full execution context of SQL cannot be determined, choose to ignore rather than report a false positive
  • Require sufficient evidence: only report issues when there is clear evidence of a problem
  • Prefer false negatives over false positives: maintain high-precision issue identification to avoid drowning real issues in excessive false reports