Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.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
Java 如何在Spring3.0中使用依赖字段?_Java_Spring_Spring Mvc - Fatal编程技术网

Java 如何在Spring3.0中使用依赖字段?

Java 如何在Spring3.0中使用依赖字段?,java,spring,spring-mvc,Java,Spring,Spring Mvc,我试图创建我的第一个SpringMVC应用程序。我使用的是体系结构:SpringMVC服务DAO持久化体系结构。 我得到了这个错误: Field error in object 'rooms' on field 'roomTypeId': rejected value [7]; codes [typeMismatch.rooms.roomTypeId,typeMismatch.roomTypeId,typeMismatch.mypackage.domain.RoomType,typeMis

我试图创建我的第一个SpringMVC应用程序。我使用的是体系结构:SpringMVC服务DAO持久化体系结构。 我得到了这个错误:

Field error in object 'rooms' on field 'roomTypeId': rejected value [7]; codes    [typeMismatch.rooms.roomTypeId,typeMismatch.roomTypeId,typeMismatch.mypackage.domain.RoomType,typeMismatch]; arguments 
[org.springframework.context.support.DefaultMessageSourceResolvable: codes   [rooms.roomTypeId,roomTypeId]; arguments []; default message [roomTypeId]]; 
default message [Failed to convert property value of type 'java.lang.String' to required type   'mypackage.domain.RoomType' 
for property 'roomTypeId'; nested exception is java.lang.IllegalStateException: 
Cannot convert value of type [java.lang.String] to required  type [mypackage.domain.RoomType] for property 
'roomTypeId': no matching editors or  conversion strategy found]
域:

@实体
@表(name=“房间”)
@XmlRootElement
@命名查询({
@NamedQuery(name=“Rooms.findAll”,query=“从房间r中选择r”)}
公共教室实现了可序列化{
...
@JoinColumn(name=“RoomTypeId”,referencedColumnName=“RoomTypeId”)
@许多酮
私人RoomType RoomType ID;
...
公共RoomType getRoomTypeId(){
返回roomTypeId;
}
public void setRoomTypeId(RoomType roomTypeId){
this.roomTypeId=roomTypeId;
}     
} 
控制器:

@RequestMapping(value=“/room/add”,method=RequestMethod.POST)
公共字符串addRoom(@modeldattribute(“rooms”)rooms,
BindingResult(结果){
房间服务。添加房间(房间);
返回“重定向:/rooms”;
}
我试过:

@RequestMapping(value=“/room/add”,method=RequestMethod.POST)
公共字符串addRoom(@modeldattribute(“rooms”)rooms rooms,@RequestParam Long roomTypeId,
BindingResult(结果){
setRoomTypeId(typeService.getType(roomTypeId.intValue());
房间服务。添加房间(房间);
返回“重定向:/rooms”;
}
jsp:



我明白这说明了什么。但我不知道如何修复它。请帮助我修复它或告诉我我做错了什么。

在下面的方法声明中

public String addRoom(@ModelAttribute("rooms") Rooms room, @RequestParam Long roomTypeId, BindingResult result...,

BindingResult
参数放在
Rooms
参数旁边

在继续之前,在
公共字符串addRoom(@ModelAttribute(“rooms”)rooms rooms,@RequestParam Long roomTypeId,BindingResult…
中,将
BindingResult
参数放在
rooms
参数旁边。非常感谢。这是一项工作=)