JAVA-077 / Advanced
Dynamic table names using MyBatis <include>/${}
Why is this a problem?
Table and column names cannot be bound, so input becomes an identifier directly.
How to fix it
java
String table = Map.of("user", "users", "order", "orders").get(type); // Server-side allowlist
if (table == null) throw new IllegalArgumentException(); xml
SELECT * FROM ${tableName} WHERE id = #{id} <!-- tableName must pass the allowlist -->