• MyBatis优化技巧


    ☬配置日志文件

     

    封装工具类

     

     

     代码贴一下:

     1 package com.shxt.utils;
     2 
     3 import java.io.InputStream;
     4 
     5 import org.apache.ibatis.io.Resources;
     6 import org.apache.ibatis.session.SqlSession;
     7 import org.apache.ibatis.session.SqlSessionFactory;
     8 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
     9 
    10 public class MyBatisUtils {
    11     private MyBatisUtils(){};
    12     private static SqlSessionFactory sqlSessionFactory=null;
    13     private static final String PATH="config.xml";
    14     private static InputStream inputStream = null;
    15     static{
    16         try{
    17             inputStream=Resources.getResourceAsStream(PATH);
    18             sqlSessionFactory =new SqlSessionFactoryBuilder().build(inputStream);
    19         }catch(Exception e){
    20             System.out.println("加载MyBatis核心文件错误。异常信息为:"+e.getMessage());
    21         }
    22     }
    23     public static SqlSession getSqlSession(){
    24         return sqlSessionFactory.openSession();
    25     }
    26     public static void closeSqlSession(SqlSession sqlSession){
    27         if(sqlSession!=null)sqlSession.close();
    28     }
    29 }

     

     

  • 相关阅读:
    J2EE第四周
    J2EE 第三周
    jsf简单入门
    Applrt和Ajax
    hello.java分析
    filter用户例子
    分析LogFilter
    理解session
    关于XML
    企业级应用和互联网应用的区别
  • 原文地址:https://www.cnblogs.com/jiangxiulian/p/5894033.html
Copyright © 2020-2023  润新知