当我使用JSP分配值时,这种编码方式最终会导致类型不匹配。(
编辑
:类型不匹配打开
applicant_id
)
用例很简单:
当在“邀请申请人”屏幕上时,用户应该能够选择时间和日期并提交表单,表单将指定的时间和日期分配给申请人,反之亦然。
主控制器
@RequestMapping("/manageApplicant/invite")
public String inviteScreen(@RequestParam(value="id") int id, Model theModel) {
theModel.addAttribute("interview", new Interview());
Applicant applicants = mainService.getSpecificApplicant(id);
theModel.addAttribute("applicants", applicants);
return "invite-applicant";
}
面谈类变量声明
@OneToOne(cascade=CascadeType.PERSIST)
@JoinColumn(name="applicant_id", nullable=false)
private Applicant applicant_id;
申请人类变量声明
@OneToOne(cascade=CascadeType.PERSIST)
@JoinColumn(name="interview_id")
private Interview interview_id;
JSP
<form:form action="/management/recruitment/setInterview" modelAttribute="interview">
<form:hidden path="applicant_id" value="${applicants}"/>
Date<form:input type="DATE" path="interviewDate"/><br>
Time<form:input type="TIME" path="interviewTime"/>
<br>
<input type="submit" value="Invite for interview" id="submitButton" />
</form:form>
MySQL表
CREATE TABLE interviews(
id INT auto_increment NOT NULL, PRIMARY KEY(id),
applicant_id int(11),
interviewDate date,
interviewTime time,
CONSTRAINT `FK_Applicant` FOREIGN KEY (`applicant_id`)
REFERENCES `applicant` (`id`)
);
ALTER TABLE applicant ADD
CONSTRAINT `interviews_ibfk_1` FOREIGN KEY (`interview_id`)
REFERENCES `interviews` (`id`);
访谈DAO实施
public void saveInterview(Interview theInterview) {
// get current session
Session currentSession = sessionFactory.getCurrentSession();
// save interview
currentSession.save(theInterview);
}