⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.java

📁 sturts好例子
💻 JAVA
字号:
package com.db;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class Test {
private static Log log = LogFactory.getLog(HibernateUtil.class);
private static SessionFactory sf;
public static final ThreadLocal sessionThread = new ThreadLocal();
public Test(){}



  public static Session currentSession() throws HibernateException {  
        
	    Session s = (Session) sessionThread.get();        
        if (s == null) {  
        	try{
            SessionFactory sf = new Configuration().configure().buildSessionFactory();  
             s = sf.openSession();  
            sessionThread.set(s);     
        	}catch(Exception e){System.out.println("SessionFactory Initial error!");}
         }  
         return s;  
     }  
public static String getInfor(){
	return "this is an information";
}



public static void closeSession() {
	Session s = (Session) sessionThread.get();
	if (s != null)
		s.close();
		sessionThread.set(null);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -