JAVA-077 / 高级
MyBatis <include>/${} 动态构建表名
为什么存在问题?
表名和列名无法参数绑定,输入直接成为标识符。
如何修复
java
String table = Map.of("user", "users", "order", "orders").get(type); // 服务端允许列表
if (table == null) throw new IllegalArgumentException(); xml
SELECT * FROM ${tableName} WHERE id = #{id} <!-- tableName 必须通过允许列表 -->