我的问题是如何使用NodeEntity类中的getLabel,getX,getY,并在我的网页上显示查询结果,而不是获取“ org.neo4j.ogm.response.model”。 / strong>我不知道是否应在控制器或存储库类中使用这些get方法,以便在网页表上显示节点信息。
@NodeEntity
public class Room {
@Id @GeneratedValue
private Long id;
@Property(name = "label")
private String label;
@Property(name = "shape")
private String shape;
@Property(name = "colour")
private String colour;
@Property(name = "x")
private String x;
@Property(name = "y")
private String y;
@Relationship(type = "To")
private Collection<Room> roomTo = new ArrayList<>();
@Relationship(type = "Up")
private Collection<Room> roomUp = new ArrayList<>();
@Relationship(type = "Down")
private Collection<Room> roomDown = new ArrayList<>();
@JsonIgnoreProperties("room")
@Relationship(type = "To", direction = Relationship.INCOMING)
Collection<RelEnt> relEnts;
public Room(){
}
public String getLabel(){
return label;
}
public String getShape(){
return shape;
}
public String getColour(){
return colour;
}
public String getX() {
return x;
}
public String getY() {
return y;
}
}
存储库:
public interface NavigatorRepository extends Neo4jRepository<Room, String>{
@Query("match (r1: Room {label: {from}}), (r2: Room {label: {to}}), p = shortestPath((r1)-[*]-(r2)) unwind nodes(p) as room return room")
Iterable<Map<String, Object>> getShortestRoute(@Param("from") String from, @Param("to") String to);
}
服务:
@Service
public class NavigatorService {
@Autowired
NavigatorRepository navigatorRepository;
public Iterable<Map<String, Object>> shortestRoute(String from, String to){
return navigatorRepository.getShortestRoute(from, to);
}
}
控制器:
@Controller
public class AunController {
@RequestMapping(value = "/AUN") //this will allow you to access web page with just http://localhost:8081/
public String homePage(){
return "AUN-Web"; //uses the static html file created for the web page
}
@Autowired
NavigatorService navigatorService;
@GetMapping(value = "/navigate")
public String navigate(@RequestParam(name="from") String from, @RequestParam(name="to") String to, Model model) {
Iterable<Map<String, Object>> route = navigatorService.shortestRoute(from, to);
model.addAttribute("from", from)
.addAttribute("route", route)
.addAttribute("to", to);
return "AUN-Results";
}
@GetMapping(value = "/")
public String error(){
return "Error/404";
}
}
HTML:
<form action="/navigate" method="">
<strong><label for="ifrom">Current Location:</label></strong> <br>
<input id="ifrom" type="text" placeholder="MB" name="from"><br>
<strong><label for="ito">Destination:</label></strong> <br>
<input id="ito" type="text" placeholder="MB" name="to"><br>
<p style="line-height: 30px; width: 300px;"></p>
<button type="button" class="btn btn-success" onclick="result">Search</button>
<p style="line-height: 30px; width: 300px;"></p>
</form>
</div>
<div align="center" class="container-fluid">
<h5>Going from <span th:text="${from}">MB220</span> to <span th:text="${to}">MB265</span></h5>
<table class="table">
<tr>
<th>Label</th>
<th>X</th>
<th>Y</th>
</tr>
<tr th:each="route : ${route}">
<td th:text="${route}">Mb220</td>
</tr>
</table>
</div>
答案 0 :(得分:0)
尝试将您的foreach变量名称更改为“ routpoint”之类的名称,以使其与完整路由有所不同。