从您的stacktrace消息中:
java.lang.NullPointerException: null at org.springframework.samples.knowledgemanager.model.CPTCode.getId(CPTCode.java:30) ~[CPTCode.class:na]
这表示的
id属性
CPTCode为null,当您使用它时,该时间将引发一个
NullPointerException。
因此,要使用您的代码,请更改以下内容:
要在表单中添加带有CPTCode的选择框,请进行如下修改:
<form:form modelAttribute="encounter" method="post" action="${actUrl}"> <div > <form:select path="preSelected" items="${encounterpres}" size="5" /> </div> <form:hidden path="id"/> <td> </td> <div > <button type="submit">Add a Billing Code</button> <h3> link to delete will go here.</h3> </div></form:form>然后,使用getter和setter 将变量添加
private Integer preSelected;到您的
Encounter类中。
在您的控制器中填充遭遇代码,例如:
@ModelAttribute("encounterpres") public Map populateEncounterpres() { Map<Integer, String> encCodes = new linkedHashMap<Integer, String>(); for(CPTCode cpt: this.clinicService.findEncounterpres()){ encCodes.put(cpt.getId(), cpt.getName()); } return encCodes; }并在您的POST中进行如下修改:
@RequestMapping(value = "/patients/{patientId}/encounters/{encounterId}/pres", method = {RequestMethod.POST}) public String processUpdateCodesForm(@ModelAttribute("encounter") Encounter encounter, @PathVariable("encounterId") int eid, BindingResult result, SessionStatus status) { Encounter myencounter = this.clinicService.findEncounterById(eid); CPTCode myCode = this.clinicService.findCPTCodeById(encounter.getCodeSelected()); myencounter.addCode(myCode); return "redirect:/encounters?encounterID={encounterId}"; }


