0
我想了解如何保存一個員工與多個任務。但我甚至不知道如何開始。春季MVC休眠 - 保存對象與多個複選框
// Employee class
@Entity
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private int idNumber;
private String firstName;
private String lastName;
@ManyToOne
@JoinColumn(name = "task_id")
private Set<Task> tasks = new HashSet<Task>();
}
// Task class
@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
}
// Dao
@Override
public void saveEmployee(Employee employee) {
sessionFactory.getCurrentSession().save(employee);
}
// Controller
@RequestMapping(value = "/save", method = RequestMethod.POST)
public @ResponseBody void saveEmployee(@RequestBody Employee employee){
employeeRepository.saveEmployee(employee)
}
,如果你是指任何相關的例子的文檔或代碼,我會很感激。