我不明白为什么我在尝试sumbit my form时遇到这个错误,所以我的web应用程序中有一个Invalid property ‘siteesTypeSite[idTypeSite]’
的bean类,我试图找到解决方案,但仍然没有运气。< / p>
org.springframework.beans.InvalidPropertyException: Invalid property ‘siteesTypeSite[idTypeSite]’ of bean class [model.Sites]:
Property referenced in indexed property path ‘siteesTypeSite[idTypeSite]’ is neither an array nor a List nor a Map; returned value was [2]
我的地图有问题吗?
Sites.java映射
public class Sites implements java.io.Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@JsonBackReference("site-typeSite")
@LazyCollection(LazyCollectionOption.FALSE)
@ManyToOne
@JoinColumn(name = “idTypeSite”)
private TypeSites siteesTypeSite;
Getter/setters
}
TypeSites.java映射:
public class TypeSites implements java.io.Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="idTypeSite")
private int idTypeSite;
private String typeSite;
@LazyCollection(LazyCollectionOption.FALSE)
@JsonManagedReference("site-typeSite")
@OneToMany(mappedBy = “siteesTypeSite”,fetch = FetchType.LAZY)
// private Set<Sites> sitees= new HashSet<Sites>(0);
private List<Sites> sitees = new AutoPopulatingList<Sites>(Sites.class);
Getter/setters
}
控制器类:
@RequestMapping(method = RequestMethod.POST, produces = "application/json")
public ResponseEntity<?> create(@ModelAttribute("site") @Valid Sites site,
@ModelAttribute("typeSites") TypeSites typeSites,
@RequestParam(required = false) String searchFor,
@RequestParam(required = false,
defaultValue = DEFAULT_PAGE_DISPLAYED_TO_USER) int page,
Locale locale) {
// TypeSites test=new TypeSites("test");
// site.setSiteesTypeSite(typeSites);
// Set type = new HashSet ();
// type.add(typeSites);
siteService.save(site);
}
Angularjs代码:
$scope.createObject = function (newObjectForm) {
if (!newObjectForm.$valid) {
$scope.displayValidationError = true;
return;
}
$scope.lastAction = ‘create';
var url = $scope.url;
var config = {headers: {‘Content-Type': ‘application/x-www-form-urlencoded; charset=UTF-8′}};
$scope.addSearchParametersIfNeeded(config, false);
$scope.startDialogAjaxRequest();
$scope.sites.siteesTypeSite =JSON.parse($scope.sites.siteesTypeSite);
$http.post(url, $.param($scope.sites), config)
.success(function (data) {
$scope.finishAjaxCallOnSuccess(data, “#addObjectsModal”, false);
})
.error(function(data, status, headers, config) {
$scope.handleErrorInDialogs(status);
});
};
JSP:
<select required
ng-model=”sites.siteesTypeSite”
name=”siteesTypeSite”
>
<option ng-repeat=”typesites in page.source” value=”{{typesites}}” >{{typesites.typeSite}}</option>
</select>
我在浏览器中提交之前有这个:
Object {codeOracle: "test", codeGSM: "test", area: "test", siteesTypeSite: Object}
area: "test"
codeGSM: "test"
codeOracle: "test"
siteesTypeSite: Object
idTypeSite: 2
sitees: Array[0]
typeSite: "Public"
__proto__: Object
__proto__: Object
Edite 1:
我试图像这样使用MAP,但是同样的错误
@LazyCollection(LazyCollectionOption.FALSE)
@JsonManagedReference("site-typeSite")
@OneToMany(mappedBy="siteesTypeSite")
@MapKey//(name="typeSite")
public Map<Integer, Sites> getSitees() {
return sitees;
}
Edite 2:
我编写了类似于bellow的siteType类,但我得到了同样的错误:
@Entity
@Table(name = "TypeSites")
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property="idTypeSite")
public class TypeSites implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private int idTypeSite;
private String typeSite;
//private List<Sites> sitees = new AutoPopulatingList<Sites>(Sites.class);;
private Map<Integer, Sites> sitees;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="idTypeSite")
public int getIdTypeSite() {
return idTypeSite;
}
public void setIdTypeSite(int idTypeSite) {
this.idTypeSite = idTypeSite;
}
@LazyCollection(LazyCollectionOption.FALSE)
@JsonManagedReference("site-typeSite")
@OneToMany(mappedBy = "siteesTypeSite", cascade = CascadeType.ALL,fetch = FetchType.LAZY)
@MapKey(name="id")
public Map<Integer, Sites> getSitees() {
return sitees;
}
public void setSitees(Map<Integer, Sites> sitees) {
this.sitees = sitees;
}
@SuppressWarnings("unchecked")
public TypeSites() {
this.sitees = MapUtils.lazyMap(new HashMap<Integer,Object>(), new Factory() {
public Object create() {
return LazyList.decorate(new ArrayList<Sites>(),
FactoryUtils.instantiateFactory(Sites.class));
}
});
}