| package com.dkx.mybatis.util; |
| |
| import org.apache.ibatis.io.Resources; |
| import org.apache.ibatis.session.SqlSession; |
| import org.apache.ibatis.session.SqlSessionFactory; |
| import org.apache.ibatis.session.SqlSessionFactoryBuilder; |
| |
| import java.io.InputStream; |
| |
| |
| * @author Dkx |
| * @version 1.0 |
| * @2023/2/1414:20 |
| * @function |
| * @comment |
| * sqlsessionfactory --> sqlsession |
| */ |
| @SuppressWarnings("all") |
| public class MybatisUtils { |
| private static SqlSessionFactory sqlsessionfactory; |
| static{ |
| try{ |
| |
| String resource = "mybatis-config.xml"; |
| InputStream inputStream = Resources.getResourceAsStream(resource); |
| sqlsessionfactory = new SqlSessionFactoryBuilder().build(inputStream); |
| }catch(Exception e){} |
| } |
| |
| |
| public static SqlSession getSqlSession(){ |
| return sqlsessionfactory.openSession(); |
| } |
| } |