Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正在创建表单上的输入数据,但未传递预先存在的值,如何解决此问题? 我为我的学生设置了一个到地址的OneToMany映射,因此一个学生可能有多个地址。项目映射正确,但当我通过表单持久化数据时,会为地址生成id(用户已经创建,我只需单击添加地址,我也得到了正确的用户),但保存时值为空,下面是我的java和jsp代码段 @PostMapping(/addAddress) 公共字符串showFormForAddAddress(@RequestParam(“studentId”)int-id,Model){ Student=studentService.findStudentById(id); 地址=新地址(); model.addAttribute(“地址”,地址); 列表地址=student.getAddresses(); 地址。添加(地址); 学生地址(地址); studentService.saveStudent(student); 返回“地址表”; } @GetMapping(“/addAddress”) 公共字符串addAddress(@RequestParam(“studentId”)int-id,Model){ 地址=新地址(); 地址:setStudentId(id); model.addAttribute(“地址”,地址); 返回“地址表”; } 地址表 SRM学生关系经理(地址) 保存地址 地址一 城市 陈述 邮政编码 地址二 此外,为了确保安全,这些是我的实体 @实体 @表(name=“address”,catalog=“user\u db”) 公共课堂演讲{ @身份证 @GeneratedValue(策略=GenerationType.AUTO) @列(name=“address\u id”) 私有整数id; 私有字符串地址; 私人城市; 私有字符串状态; 私有字符串zipCode; 私有字符串地址2; @列(name=“user\u id”) 私人整数学生ID; @实体 @表(name=“Student”,catalog=“user\u db”) 公立班学生{ @身份证 @GeneratedValue(策略=GenerationType.IDENTITY) @列(name=“student\u id”) 私有int-id; 私有字符串名; 私有字符串lastName; 私人字符串电子邮件; @OneToMany(级联=级联类型.ALL) @JoinColumn(name=“学生id”,referencedColumnName=“学生id”) 私人名单地址;_Java_Hibernate_Jsp_Jstl - Fatal编程技术网

正在创建表单上的输入数据,但未传递预先存在的值,如何解决此问题? 我为我的学生设置了一个到地址的OneToMany映射,因此一个学生可能有多个地址。项目映射正确,但当我通过表单持久化数据时,会为地址生成id(用户已经创建,我只需单击添加地址,我也得到了正确的用户),但保存时值为空,下面是我的java和jsp代码段 @PostMapping(/addAddress) 公共字符串showFormForAddAddress(@RequestParam(“studentId”)int-id,Model){ Student=studentService.findStudentById(id); 地址=新地址(); model.addAttribute(“地址”,地址); 列表地址=student.getAddresses(); 地址。添加(地址); 学生地址(地址); studentService.saveStudent(student); 返回“地址表”; } @GetMapping(“/addAddress”) 公共字符串addAddress(@RequestParam(“studentId”)int-id,Model){ 地址=新地址(); 地址:setStudentId(id); model.addAttribute(“地址”,地址); 返回“地址表”; } 地址表 SRM学生关系经理(地址) 保存地址 地址一 城市 陈述 邮政编码 地址二 此外,为了确保安全,这些是我的实体 @实体 @表(name=“address”,catalog=“user\u db”) 公共课堂演讲{ @身份证 @GeneratedValue(策略=GenerationType.AUTO) @列(name=“address\u id”) 私有整数id; 私有字符串地址; 私人城市; 私有字符串状态; 私有字符串zipCode; 私有字符串地址2; @列(name=“user\u id”) 私人整数学生ID; @实体 @表(name=“Student”,catalog=“user\u db”) 公立班学生{ @身份证 @GeneratedValue(策略=GenerationType.IDENTITY) @列(name=“student\u id”) 私有int-id; 私有字符串名; 私有字符串lastName; 私人字符串电子邮件; @OneToMany(级联=级联类型.ALL) @JoinColumn(name=“学生id”,referencedColumnName=“学生id”) 私人名单地址;

正在创建表单上的输入数据,但未传递预先存在的值,如何解决此问题? 我为我的学生设置了一个到地址的OneToMany映射,因此一个学生可能有多个地址。项目映射正确,但当我通过表单持久化数据时,会为地址生成id(用户已经创建,我只需单击添加地址,我也得到了正确的用户),但保存时值为空,下面是我的java和jsp代码段 @PostMapping(/addAddress) 公共字符串showFormForAddAddress(@RequestParam(“studentId”)int-id,Model){ Student=studentService.findStudentById(id); 地址=新地址(); model.addAttribute(“地址”,地址); 列表地址=student.getAddresses(); 地址。添加(地址); 学生地址(地址); studentService.saveStudent(student); 返回“地址表”; } @GetMapping(“/addAddress”) 公共字符串addAddress(@RequestParam(“studentId”)int-id,Model){ 地址=新地址(); 地址:setStudentId(id); model.addAttribute(“地址”,地址); 返回“地址表”; } 地址表 SRM学生关系经理(地址) 保存地址 地址一 城市 陈述 邮政编码 地址二 此外,为了确保安全,这些是我的实体 @实体 @表(name=“address”,catalog=“user\u db”) 公共课堂演讲{ @身份证 @GeneratedValue(策略=GenerationType.AUTO) @列(name=“address\u id”) 私有整数id; 私有字符串地址; 私人城市; 私有字符串状态; 私有字符串zipCode; 私有字符串地址2; @列(name=“user\u id”) 私人整数学生ID; @实体 @表(name=“Student”,catalog=“user\u db”) 公立班学生{ @身份证 @GeneratedValue(策略=GenerationType.IDENTITY) @列(name=“student\u id”) 私有int-id; 私有字符串名; 私有字符串lastName; 私人字符串电子邮件; @OneToMany(级联=级联类型.ALL) @JoinColumn(name=“学生id”,referencedColumnName=“学生id”) 私人名单地址;,java,hibernate,jsp,jstl,Java,Hibernate,Jsp,Jstl,我觉得这可能是一个命名问题,但我不能完全指出这一点,而且我尝试删除帖子并仅使用get,但仍然不起作用。在您的showFormForAddAddress方法中,您编写了model.addAttribute(“address”,address);这将值放入model属性中 但是您试图从这个方法获取地址信息,这是错误的 您可以使用以下方法获取相关信息: Map<String,Object> modelMap = model.getModel().asMap(); Object object

我觉得这可能是一个命名问题,但我不能完全指出这一点,而且我尝试删除帖子并仅使用get,但仍然不起作用。

在您的
showFormForAddAddress
方法中,您编写了
model.addAttribute(“address”,address);
这将值放入model属性中

但是您试图从这个方法获取地址信息,这是错误的

您可以使用以下方法获取相关信息:

Map<String,Object> modelMap = model.getModel().asMap();
Object object = modelMap.get("address");
Map modelMap=model.getModel().asMap();
Object=modelMap.get(“地址”);

之后,您可以将结果对象转换为地址类型并使用它

这应该是ShowForAddMethod

@PostMapping(/addAddress)
公共字符串showFormForAddAddress(@RequestParam(“studentId”)int-id,Model-Model,
@ModelAttribute(“地址”)地址(地址){
Student=studentService.findStudentById(id);
model.addAttribute(“地址”,地址);
列表地址=student.getAddresses();
地址。添加(地址);
学生地址(地址);
studentService.saveStudent(student);
返回“重定向:/student/list”;
}
如果我创建了一个新对象,则信息不会被映射,因此它会丢失,但当我在参数中将address作为模型属性传递时,它会指向student对象