package cn.word.util;
import java.io.IOException;import java.io.InputStream;import java.util.Enumeration;import java.util.HashMap;import java.util.Map;import javax.servlet.http.HttpServletRequest;
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 factory; static{ try { InputStream inputStream= Resources.getResourceAsStream("mybatis-config.xml"); factory = new SqlSessionFactoryBuilder().build(inputStream); } catch (IOException e) { e.printStackTrace(); } } public static Map getPara(HttpServletRequest request){ Map map = new HashMap(); Enumeration<String> enumeration = request.getParameterNames(); while(enumeration.hasMoreElements()){ String key = enumeration.nextElement(); String[] values = request.getParameterValues(key); if(values.length == 1){ String value = values[0]; map.put(key, value); } } return map; } public static SqlSession createSqlSession(){ return factory.openSession(false); } public static void closeSqlSession(SqlSession sqlSession){ if(null!=sqlSession){ sqlSession.close(); } }}