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 은 화이트리스트 통과값만 -->