日期:2014-05-16 浏览次数:20353 次
实体:
?dao:
public void saveObject(CarInfo o) { Session session = this.getSessionFactory().openSession(); try{ session.save(o); session.flush(); session.close(); }catch(Exception e){ if(session != null){ session.close(); } } finally { if(session.isOpen()){ session.close(); } } }
?
service:
public void saveObject(CarInfo o) { this.carInfoDao.saveObject(o); }
?页面导入图片的bean方法
public void test(UploadEvent event){ UploadItem item = event.getUploadItem(); try { FileInputStream fis = new FileInputStream(item.getFile());//定义文件读入流 ByteArrayOutputStream bytestream = new ByteArrayOutputStream(); Blob blob = Hibernate.createBlob(fis); carInfo.setPicFile(blob); fis.close(); bytestream.close(); } catch (Exception e) { e.printStackTrace(); } }
?
bean的保存对象的方法
public String addSave(){ this.carInfoManager.saveObject(carInfo); }
?