我正在尝试创建一个“添加员工表单”,其中包含用户可以填写的基本属性,例如姓名性别电子邮件等
在表单中,将为可用的部门提供下拉选项,其中列表将由将从控制器发送的 linkedhashmap 预先填充
我已经在我的模型中添加了一个属性对象类型“Employee”,所以当我填写表格时
并返回控制器,员工对象将自动设置
Controller.java
@GetMapping("/showFormForAdd")
public String showFormForAdd(Model theModel) {
//fetch new list(if any) of departments added
List<Department> theDepartments = departmentService.getDepartments();
//Create a linkedhash map to hold our department_id-department name information
final LinkedHashMap<Integer, String> departmentOptions = departmentService.generateDepartmentOptions(theDepartments);
// create new employee object and attach to our model atrribute.
//how to add multiple objects?? doing this so i can pre-populate available departments for selection
theModel.addAttribute("employee", departmentOptions);
Employee theEmployee = new Employee();
//how to add multiple objects?? doing this so when program return control to controller it will help me set the attribute of employees so I can save it into the database
theModel.addAttribute("employee", theEmployee);
return "customer-form";
}
问题:我如何将多个属性(例如,员工对象和 linkedhashmap)添加到我的模型中,以便我可以预填充选择框,同时为我的控制器提供方法来为我的员工对象设置属性并保存到我的当我将控制权返回给控制器时数据库?
任何帮助将不胜感激..谢谢!
编辑:只是一个更新,提供的每个答案都有效..我被混淆了。
烙印99
侃侃尔雅
相关分类