Java 如何从窗体将对象作为属性发送

Java 如何从窗体将对象作为属性发送,java,spring,hibernate,Java,Spring,Hibernate,春天,冬眠。 我有一个QuestionEntity,其中包含另一个实体(TestEntity): 从html页面我想添加TestEntity作为对象(逻辑是:测试有问题) 但是spring将${testEntity}作为字符串获取,因此我有一个错误: 字段“testEntity”上的对象“question”中存在字段错误:值被拒绝 [TestEntity{id=3,name='Узаааааааааааааа1072;代码 [typeMismatch.question.testEntity,ty

春天,冬眠。 我有一个QuestionEntity,其中包含另一个实体(TestEntity):

从html页面我想添加TestEntity作为对象(逻辑是:测试有问题)

但是spring将${testEntity}作为字符串获取,因此我有一个错误:

字段“testEntity”上的对象“question”中存在字段错误:值被拒绝 [TestEntity{id=3,name='Узаааааааааааааа1072;代码 [typeMismatch.question.testEntity,typeMismatch.testEntity,typeMismatch.exampro.entity.testEntity,typeMismatch]; 论据 [org.springframework.context.support.DefaultMessageSourceResolvable: 代码[question.testEntity,testEntity];参数[];默认消息 [测试];默认消息[无法转换的属性值] 将“java.lang.String”键入所需类型“exampro.entity.TestEntity” 对于属性“testEntity”;嵌套异常为 java.lang.IllegalStateException:无法转换类型的值 将“java.lang.String”改为所需类型“exampro.entity.TestEntity” 属性“testEntity”:没有匹配的编辑器或转换策略 发现]


如何正确发送?非常感谢您的帮助。

您是否用hibernate搜索过如何从表单访问java属性?是的,我使用@PostMapping(“addQuestion”)公共字符串addQuestion(@ModelAttribute(“question”)QuestionEntity QuestionEntity){questionService.saveOrUpdate(question}我会将其添加到帖子中
public class QuestionEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

@Column(name = "question_text")
private String questionText;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "test_id")
private TestEntity testEntity; ...}
<form name="question" action="/exam/addQuestion/" method="post">
Текст вопроса:<br>
<input type="text" name="questionText.text">
<input type="hidden" name="testEntity" value="${testEntity}">
<input type="submit" name="addTest" value="add">
    @PostMapping("addQuestion")
public String addQuestion(@ModelAttribute ("question") QuestionEntity questionEntity){
    testService.saveOrUpdate(questionEntity);
    return "redirect:/exam/getall";
}