gpt4 book ai didi

java - 从 hibernate 检索几何对象到 angular.js

转载 作者:太空宇宙 更新时间:2023-11-04 14:55:59 25 4
gpt4 key购买 nike

我正在尝试查看 map 上存储在 postgreSQL 数据库中的一些对象。使用的框架是 spring 和 hibernate,前端是 angular.js。我已经检查了从 hibernate 返回的对象的 Controller 类、服务类。在类(class)水平上,他们都很好。但是当我检查 js (angular.js) 时,它有对象和数字。由于代码需要对象而不是数字,因此会发生错误。返回对象与此类似。

Array[5]
0:Object
1:20
2:Object
3:24
4:13
length:5

数组包含从 Controller 类返回的结果。在 map 上查看第一个对象。由于第二个是数字而不是对象,因此会生成错误。这是将对象返回到 angular.js 脚本的代码块。

@RequestMapping(value = "/crimerecode/getall.htm", method = RequestMethod.GET)
@ResponseBody
public List<CrimeRecord> getAllCrimeRecords(@RequestParam String startDate,@RequestParam String endDate) {
try {
// crds.invalidateCrimeRecord(cr.getGcrno());
System.out.println("=========controller===============");
for(int i=0;i<(crds.getAll(startDate, endDate)).size();i++){
System.out.println(((crds.getAll(startDate, endDate)).get(i).getTheGeom()));
}
return crds.getAll(startDate, endDate);
}
catch (ParseException ex) {
java.util.logging.Logger.getLogger(CrimeRecordController.class.getName()).log(Level.SEVERE, null, ex);
}

return null;
}

这是 Angular 脚本中的代码块...

$http.get('/CMISystem/crimerecode/getall.htm?startDate=' + $scope.startDate + '&endDate=' +
$scope.endDate
).
success(function(data) {
console.log(data);
alert(data);
data.forEach(function(value) {

console.log(value);

var geo = value.theGeom.geo;

var point = new OpenLayers.Geometry.Point(geo.lon, geo.lat);
point.transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
var pointFeature = new OpenLayers.Feature.Vector(point, value);
.....
}

我只在这里发布了类和javascript中的相关代码...

最佳答案

我认为问题出在 List<CrimeRecord>你从你的getAllCrimeRecords返回方法。

尝试创建一个数组列表并添加每个 CrimeRecord对象,添加到您的数组列表,如以下示例所示。

public List<CrimeRecord> getAllCrimeRecords(@RequestParam String startDate, @RequestParam String endDate) {
List<CrimeRecord> cr = new ArrayList<CrimeRecord>();
try {

for (int i = 0; i < (crds.getAll(startDate, endDate)).size(); i++) {
cr.add(crds.getAll(startDate, endDate).get(i));
}

} catch (ParseException ex) {
java.util.logging.Logger.getLogger(CrimeRecordController.class.getName()).log(Level.SEVERE, null, ex);
}

return cr;
}

关于java - 从 hibernate 检索几何对象到 angular.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23191186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com