[英]how to read generated sql statement from annotation-configured Mybatis mapper
我将MyBatis 3.2.3与Spring 3.2.5结合使用,并具有基于注释的配置。
我有一些POJO,它们调用生成的Mapper接口来执行SQL查询。
是否可以检索映射器正在执行的SQL语句? 如果我使用的是DAO扩展了SqlMapClientDaoSupport的DAO,则可以理解如何执行此操作,但是由于我现在仅使用映射器接口,因此我不确定如何获取对生成的SQL的引用。
任何指针表示赞赏。
实际上,可以在Spring配置的应用程序中执行此操作,而无需使用插件/拦截器:
SqlSessionFactory s = (SqlSessionFactory) ctx.getBean("sqlSessionFactory");
Configuration configuration = s.getConfiguration();
MappedStatement ms = configuration.getMappedStatement("MyStatementId");
BoundSql boundSql = ms.getBoundSql(parameters); // pass parameters for the SQL statement
System.out.println("SQL" + boundSql.getSql());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.