首页>代码>Spring+Spring MVC+Mybatis+Jersey+Fastjson整合RESTful API框架,适合学习RESTful API框架初学者>/NICO-DEMO-Api/src/main/java/com/nico/utils/IBatisUtil.java
package com.nico.utils; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class IBatisUtil { public static <T> Object get(Class<T> object) { ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-mybatis.xml"); SqlSessionFactory sessionFactory = (SqlSessionFactory) applicationContext.getBean("sqlSessionFactory"); /* 获得session 获得的这个session是默认提交事务 */ SqlSession session = sessionFactory.openSession(true); T model = session.getMapper(object); return model; } }
最近下载更多