調用getCurrentSession方法需要在主配置文件中添加一個配置 image.png 通過getCurrentSession方法得到的session對象,一定不要手動關閉session 因為transaction對象會給關閉。此處體現hibernate封裝的threadlocal很完美。