我正在尝试使用休眠将Bean对象插入mysql列中。现在,当用户使用文本字段添加数据时,它将逐行添加数据。我在尝试时如何实现此目的,但找不到合适的解决方案。 这是我的控制器代码-
featureBean.setFeature_1(request.getParameter("param1").trim());
featureBean.setFeature_2(request.getParameter("param2").trim());
featureBean.setFeature_3(request.getParameter("param3").trim());
featureBean.setFeature_4(request.getParameter("param4").trim());
featureBean.setFeature_5(request.getParameter("param5").trim());
featureBean.setFeature_6(request.getParameter("param6").trim());
featureBean.setFeature_status("Add");
int results = addParameterinterface.addFeature(featureBean);
if (results > 0) {
jsonobject.put("message", "success");
LOG.info("product Feature is Added successfully");
} else {
LOG.info("product Feature is not Added successfully");
}
break;
现在的Impl代码-
LOG.info("addFeature is called in AddCategoryDAOImpl class");
int result;
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
try (Session session = sessionFactory.openSession()) {
Transaction tx = session.beginTransaction();
result = (Integer) session.save(featureBean);
tx.commit();
LOG.info("Feature detail is Added with an id" + result);
if (result > 0) {
LOG.info("something went wrong");
} else {
LOG.info("Feature detail is Added with an id" + result);
}
}
return result;
希望任何人都能给出期望的结果。在此先感谢