我正在关注 SpringBoot + MyBatis 教程。我能够将简单的对象插入数据库。例如,我尝试插入一个员工对象:
Employee{
private String id;
private String name;
}
@Mapper
public interface EmployeeMapper {
@Insert("insert into employee(id,name) values(#{id},#{name})")
void insert(Employee employee);
}
现在我想插入另一个对象,如下所示:
Department{
// deptId will be common for all employees in the map
private int deptId;
//employeeMap is a Map employees where employeeId is key and employeeName is value
private Map<String, String> employeeMap;
}
//Eg. I have the following data in Department Object
Department dept = new Department();
dept.setId("d1");
Map<String, String> employeeMap = new HashMap<String, String>();
employeeMap.put("1","Jon");
employeeMap.put("2","Doe");
employeeMap.put("3","Sam");
dept.setEmployeeMap(employeeMap);
// I want to insert dept object as 3 columns in database
//*deptId* will be common for all employees in Map
//*employeeId* key of map
//*employeeName* valiue of map
我无法解决它,这不能像简单的员工示例中那样使用@Insert 来完成。请帮忙,因为我被困在这个问题上。