Skip to content

Instantly share code, notes, and snippets.

@qsLI
Created August 13, 2018 04:26
Show Gist options
  • Save qsLI/39113754732a08674d9f09fcce2533f5 to your computer and use it in GitHub Desktop.
Save qsLI/39113754732a08674d9f09fcce2533f5 to your computer and use it in GitHub Desktop.
test mybatis mapper
@Test
public void countExpiredUser() throws IllegalAccessException {
final Field mappedStatements = ReflectionUtils.findField(Configuration.class, "mappedStatements");
mappedStatements.setAccessible(true);
final Map<String, MappedStatement> stringMappedStatementMap =
(Map<String, MappedStatement>)mappedStatements.get(config);
stringMappedStatementMap.forEach(
(k, v) -> {
if (StringUtils.isNotBlank(k) && k.startsWith(namespace)) {
final SqlSource sqlSource = v.getSqlSource();
final HashMap<String, Object> params = Maps.newHashMap();
params.put("endTime", new Date());
final BoundSql boundSql = sqlSource.getBoundSql(params);
System.out.println(k + " -> " + boundSql.getSql());
}
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment