Skip to content

Instantly share code, notes, and snippets.

@qsLI
Created May 10, 2018 08:40
Show Gist options
  • Save qsLI/ec62f13eb128271fc8b199d2fed5c819 to your computer and use it in GitHub Desktop.
Save qsLI/ec62f13eb128271fc8b199d2fed5c819 to your computer and use it in GitHub Desktop.
package com.qunar.mobile.dao.order.hotel.impl;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.apache.ibatis.builder.annotation.ProviderSqlSource;
import org.apache.ibatis.builder.xml.XMLConfigBuilder;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.scripting.xmltags.DynamicSqlSource;
import org.apache.ibatis.session.Configuration;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Properties;
/**
* @author qisheng.li
* @email [email protected]
* @date 18-5-10 下午3:32
*/
public class HotelOrderSimpleDaoImplTest {
@Test
public void testSql() throws IOException {
String resource = "mybatis-config.xml";
try (InputStream inputStream = Resources.getResourceAsStream(resource)) {
XMLConfigBuilder builder = new XMLConfigBuilder(inputStream, null, new Properties());
Configuration config = builder.parse();
System.out.println("config = " + config);
final MappedStatement mappedStatement = config.getMappedStatement("hotelOrderSimple.countOrder");
final DynamicSqlSource sqlSource = (DynamicSqlSource) mappedStatement.getSqlSource();
final HashMap<String, Object> params = Maps.newHashMap();
params.put("uids", Sets.newHashSet("1", "2", "3"));
final BoundSql boundSql = sqlSource.getBoundSql(params);
System.out.println(boundSql.getSql());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment