model类 一下情况分别是一对一 和 一对多 至于多对多的关系 只要建立中间表的model类应该可以实现(我没测试因为我的多对多的关联没有建中间表的model)

private CmsQuestionType cmsQuestionType;

private List cmsQuestionOptions;


@Valid //加上@Valid注解即可级联验证 被关联那方只在属性上做判断就行

@ManyToOne(fetch = FetchType.LAZY)

@JoinColumn(name = "question_type_id")

public CmsQuestionType getCmsQuestionType() {

return this.cmsQuestionType;

}


public void setCmsQuestionType(CmsQuestionType cmsQuestionType) {

this.cmsQuestionType = cmsQuestionType;

}

@Valid

@OneToMany(fetch = FetchType.LAZY, mappedBy = "cmsQuestion")

public List getCmsQuestionOptions() {

return this.cmsQuestionOptions;

}


public void setCmsQuestionOptions(List cmsQuestionOptions) {

this.cmsQuestionOptions = cmsQuestionOptions;

}

@valid

@ManyToMany(fetch = FetchType.LAZY)

@JoinTable(name = "tb_cms_klpoint_question", 

joinColumns = { @JoinColumn(name = "question_id", nullable = false, updatable = false) }, 

inverseJoinColumns = { @JoinColumn(name = "knowledge_point_id", nullable = false, updatable = false) })

public List getCmsKnowledgePoints() {

return this.cmsKnowledgePoints;

}

public void setCmsKnowledgePoints(List cmsKnowledgePoints) {

this.cmsKnowledgePoints = cmsKnowledgePoints;

}

jsp代码

one to one

one to many

many to many还没测试以后补起来