Spring:@modeldattribute和数组php
我需要将PHP数组映射到Javabean 这是映射表单的我的bean:Spring:@modeldattribute和数组php,php,spring,spring-mvc,modelattribute,Php,Spring,Spring Mvc,Modelattribute,我需要将PHP数组映射到Javabean 这是映射表单的我的bean: public class SearchModel{ private String id; private String user; private List<SearchRoom> rooms; //get and set } 这就是我试图用PHP发送的内容: Array ( [id] => xxx [rooms] => Array (
public class SearchModel{
private String id;
private String user;
private List<SearchRoom> rooms;
//get and set
}
这就是我试图用PHP发送的内容:
Array
(
[id] => xxx
[rooms] => Array
(
[0] => Array
(
[adults] => 3
[child] => 2
[childrenAges] => Array
(
[0] => 2
[1] => 5
)
)
[1] => Array
(
[adults] => 2
[child] => 0
[childrenAges] => Array
(
)
)
[2] => Array
(
[adults] => 2
[child] => 4
[childrenAges] => Array
(
[0] => 1
[1] => 4
[2] => 12
[3] => 17
)
)
)
[user] => yyy
)
我得到了一个例外:
Invalid property 'rooms[0][adults]' of bean class [com.giove.viaggi.hsw.models.SearchModel]: Property referenced in indexed property path 'rooms[0][adults]' is neither an array nor a List nor a Map; returned value was [3]] with root cause
org.springframework.beans.InvalidPropertyException: Invalid property 'rooms[0][adults]' of bean class [com.giove.viaggi.hsw.models.SearchModel]: Property referenced in indexed property path 'rooms[0][adults]' is neither an array nor a List nor a Map; returned value was [3]
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1046)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:922)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:82)
at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:728)
at org.springframework.validation.DataBinder.doBind(DataBinder.java:624)
at org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:189)
什么是避免该错误并检索正确值的好解决方案?PHP和JAVA?真的有可能吗?和你为什么要这样做 我认为这是不可能的,因为Java和PHP是不同的技术 无效属性“rooms[0][成人]的错误告诉您它找不到rooms数组。
这很正常,您没有在java页面中声明该数组,但在php中,我解决了将php数组转换为xml字符串并使我的控制器接受xml并使用jaxb将其转换为我的bean的问题。这是可能的:如果我删除rooms数组,另一个字段将正确映射到java bean的两个字符串。
Array
(
[id] => xxx
[rooms] => Array
(
[0] => Array
(
[adults] => 3
[child] => 2
[childrenAges] => Array
(
[0] => 2
[1] => 5
)
)
[1] => Array
(
[adults] => 2
[child] => 0
[childrenAges] => Array
(
)
)
[2] => Array
(
[adults] => 2
[child] => 4
[childrenAges] => Array
(
[0] => 1
[1] => 4
[2] => 12
[3] => 17
)
)
)
[user] => yyy
)
Invalid property 'rooms[0][adults]' of bean class [com.giove.viaggi.hsw.models.SearchModel]: Property referenced in indexed property path 'rooms[0][adults]' is neither an array nor a List nor a Map; returned value was [3]] with root cause
org.springframework.beans.InvalidPropertyException: Invalid property 'rooms[0][adults]' of bean class [com.giove.viaggi.hsw.models.SearchModel]: Property referenced in indexed property path 'rooms[0][adults]' is neither an array nor a List nor a Map; returned value was [3]
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1046)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:922)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:82)
at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:728)
at org.springframework.validation.DataBinder.doBind(DataBinder.java:624)
at org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:189)