I have a Spring MVC application that I am building, using an Oracle Spatial database which contains 3D geometries. I'm using Hibernate Spatial to access it, but as I am new to Spring (and relatively new to Java), I am finding it difficult to access the z-coordinate for my view. Code below:
package com.example.project.model;
import com.vividsolutions.jts.geom.Point
import ...
@Entity
@Table(name="DEPOSITS")
public class Deposit {
@Id
@Column(name = "ID")
private int id;
@Column(name = "NAME")
private String name;
@Column(name = "GEOM",updatable = false)
@Type(type="org.hibernate.spatial.GeometryType")
private Point geometry;
public Point getGeometry() {
return geometry;
}
}
package com.example.project;
import ...
@Controller
public class DepositController {
private DepositService depositService;
@Autowired(required = true)
@Qualifier(value = "depositService")
public void setDepositService(DepositService ds) {
this.depositService = ds;
}
//Index
@RequestMapping(value = "/deposits", method = RequestMethod.GET)
public String listDeposits(Model model) {
model.addAttribute("listDeposits", this.depositService.listDeposits());
return "deposits/index";
}
}
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ page session="false" %>
<html>
<head>
<title>Deposits Page</title>
</head>
<body>
<c:if test="${!empty listDeposits}">
<table>
<tr>
<th>Deposit ID</th>
<th>Deposit Name</th>
<th>Longitude</th>
<th>Latitude</th>
<th>Height</th>
</tr>
<c:forEach items="${listDeposits}" var="deposit">
<tr>
<td>${deposit.id}</td>
<td>${deposit.name}</td>
<td>${deposit.geometry.x}</td>
<td>${deposit.geometry.y}</td>
<td>${deposit.geometry.coordinate.z}</td>
</tr>
</c:forEach>
</table>
</c:if>
</body>
</html>
I know that the Point type for JTS does not expose the z-coordinate, and that it can accessed through the coordinates object. The code deposit.getGeometry().getCoordinates().z
works, how do I make it work for my .jsp view?
Thanks
I suspect that ${deposit.geometry.x}
is being rewritten into deposit.getGeometry().getX()
and getX() is a method that exists on that class, so it works.
Similarly, ${deposit.geometry.coordinate.z}
would be rewritten to deposit.getGeometry().getCoordinate().getZ()
, which is not a method that exists.
I would just add getters for X, Y and Z to the Deposit class and then use
${deposit.x}
${deposit.y}
${deposit.z}