我有两个组合框,我想从第一个组合框中选择的选项中获取值,并且列表出现在要在第一个组合框中选择的类对象中
E.g 我有两个分支账户和立法 帐户还有两个子分支:财务,财务报表,它们作为列表存在于分支对象中
立法:问题,决议
当用户选择帐户时,第二个组合框会自动将帐户对象中的列表加载到第二个组合框中
第一个组合框 - 选定的帐户 第二个组合框 - 显示财务,财务报表
<option />
<c:forEach items="${branchList}" var="branch">
<option value="${branch.branchName}">${branch.branchName}</option>
</c:forEach>
</select>
<td>Sub Branch</td>
<td> <select name="subBranchName" >
<c:forEach items="${subBranchList}" var="subBranch">
<option value="${subBranch.subBranchName}">${subBranch.subBranchName}</option>
</c:forEach>
</select> </td>
我的分类:
@Entity
@NamedQuery(name="Branch.findAll", query="SELECT b FROM Branch b")
public class Branch {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="BRANCH_ID")
private long branchId;
@Column(name="BRANCH_NAME")
private String branchName;
//bi-directional many-to-one association to EmployeeDetail
@OneToMany(mappedBy="branch")
private List<EmployeeDetail> employeeDetails;
//bi-directional many-to-one association to SubBranch
@OneToMany(mappedBy="branch")
private List<SubBranch> subBranches;
// Getters & Setters
我的控制器:
@RequestMapping("createFile")
public ModelAndView createFile(@ModelAttribute Employee employee , Model model) {
List<Branch> branchList = branchService.getList();
model.addAttribute("branchList", branchList);
ArrayList<String> documentType = new ArrayList<String>();
documentType.add("PUC");
documentType.add("Annex");
model.addAttribute("documentType", documentType);
String notings = " ";
model.addAttribute("notings", notings);
logger.info("branch : "+branchList.get(1).getBranchName());
List<SubBranch> subBranchList = new ArrayList<SubBranch>();
subBranchList = subBranchService.getList();
model.addAttribute("subBranchList", subBranchList);
List<EmployeeDetail> employeeDetailList = employeeDetailService.getList();
model.addAttribute("employeeDetailList", employeeDetailList);
MultipartFile file = null ;
model.addAttribute("fileUpload", file);
return new ModelAndView("createNewFile");
}
当我单独加载子分支列表时,代码工作正常,但我想从分支的值加载子分支列表,即当选择分支时,程序自动加载子分支列表,分支列表存在于Branch类中,该类是我要加载到子分支列表中的值
我是Spring MVC的新手,并且不知道如何在不调用控制器的情况下加载值。
提前致谢