У меня вопрос Как я могу использовать мои getLabel, getX, getY из моего класса NodeEntity и отображать результаты моего запроса на моей веб-странице вместо того, чтобы получать "org.neo4j.ogm.response.model". Я не знаю, следует ли использовать эти методы 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>