MyBatisUtil

package com.it.util;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class MyBatisUtil {
	private static SqlSessionFactory sf;
	static {
		try {
			Reader reader = Resources.getResourceAsReader("mybatis.xml");
			sf = new SqlSessionFactoryBuilder().build(reader);
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	public static SqlSession getSession() {
		return sf.openSession();
	}
}

posted on 2016-06-05 11:56  菜鸟Z  阅读(127)  评论(0编辑  收藏  举报

导航