我想为拯救学生这两个方法。现在我想用这个。这是我的方法:
@Override
public void save(T entity) {
Session session = getSession();
Transaction transaction = session.beginTransaction();
session.saveOrUpdate(entity);
transaction.commit();
session.close();
}
@Override
public void save(Set<T> entity) {
Session session = getSession();
Transaction transaction = session.beginTransaction();
for (T t : entity) {
session.saveOrUpdate(t);
}
transaction.commit();
session.close();
}
使用它们为ex添加学生我为它写了一个实例:
static IStudentDao stDao = new StudentDao();
and wite this :
stdId = Console.getInputInteger("enter your code");
int stage = Console.getInputInteger("enter your age");
String stname = Console.getInputString("enter your name:");
String stlname = Console.getInputString("enter your lastname:");
String stfname = Console.getInputString("enter your fathername:");
String stmajor = Console.getInputString("enter your major:");
Student student = new Student();
student.setFirstName(stname);
student.setLastName(stlname);
student.setAge(stage);
student.setFatherName(stfname);
student.setMajor(stmajor);
student.setStudentcode(stdId);
IStudentDao.save();
repository.showStudents();
但它出错了。我不知道应该发送什么:
IStudentDao.save();
答案 0 :(得分:0)
您的IStudentDao::save
不是静态的,因此您无法将其称为IStudentDao.save()
。
您必须在IStudentDao
的{{1}}实例上调用方法:
stDao