hibernatesessionfactory.java
来自「这是一个购物车的源码」· Java 代码 · 共 25 行
JAVA
25 行
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 + =
减小字号Ctrl + -
显示快捷键?