📄 hibernatesessionfactory.java
字号:
package com.tarena.util;import org.hibernate.HibernateException;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.cfg.Configuration;public class HibernateSessionFactory { private static SessionFactory sf=null; public static ThreadLocal local=new ThreadLocal(); // <property name="current_session_context_class">thread</property><!-- 要使用getCurrentSession()必须就得加这句话 --> static{ try { Configuration cfg=new Configuration(); sf=cfg.configure().buildSessionFactory(); } catch (HibernateException e) { e.printStackTrace(); } } public static Session getSession(){ if(sf==null) return null; return sf.getCurrentSession(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -