/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mybatis;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.InputStream;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
import org.mybatis.generator.Addresses;
import org.mybatis.generator.AddressesMapper;
/**
*
* @author Ryan
*/
public class MyBatis {
//log4j setup
static Logger logger = Logger.getLogger("MyBatis.class");
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
BasicConfigurator.configure();
try {
String mapconfig = "mybatis/res/MapperConfig.xml";
InputStream inputStream = Resources.getResourceAsStream(mapconfig);
SqlSessionFactory sqlSession = new SqlSessionFactoryBuilder().build(inputStream);
SqlSession session = sqlSession.openSession();
try {
AddressesMapper mapper = session.getMapper(AddressesMapper.class);
Addresses addresses = mapper.selectByPrimaryKey(101);
} finally {
session.close();
}
}
catch( Exception ex) {
ex.printStackTrace();
}
}
}