스프링에서 xml 처리하지않고 직접 xml 을 호출하면서 처리하는 예제.
인터넷이 되지않는 프로젝트에서 사용하려고 기록한다.
java 부분.
String resource = "mybatis-config.xml";
InputStream inputStream = null;
try {
inputStream = Resources.getResourceAsStream(resource);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
SqlSession session = sqlSessionFactory.openSession();
List<HashMap> sss = session.selectList("testman.selectTest");
for (int a = 0; a < sss.size() ; a ++)
{
HashMap res = sss.get(a);
System.out.println("=====>" + res.get("ID"));
}
mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl"/>
<property name="username" value="user"/>
<property name="password" value="user"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="test.xml"/>
</mappers>
</configuration>
mapper xml ( test.xml )
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="testman">
<select id="selectTest" resultType="hashmap">
SELECT *FROM TTT
</select>
</mapper>
'Developer > API' 카테고리의 다른 글
Apache POI - Excel 넓이 (0) | 2013.10.02 |
---|