Доброе время суток. POJO
| Код | @Entity @NamedQuery(name = "allOpers", query = "SELECT o FROM Opers o") public class Opers { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; private String name; private String surname; @ManyToOne private Filials filials; public Opers() { super(); // TODO Auto-generated constructor stub } public Opers(int id, String name, String surname, Filials filials) { super(); this.id = id; this.name = name; this.surname = surname; this.filials = filials; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSurname() { return surname; } public void setSurname(String surname) { this.surname = surname; } public Filials getFilials() { return filials; } public void setFilials(Filials filials) { this.filials = filials; } @Override public String toString() { return "Opers [id=" + id + ", name=" + name + ", surname=" + surname + ", filials=" + filials + "]"; } }
|
И есть страница
| Код | <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Opers</title> </head> <body> <sf:form modelAttribute="opers" action="${pageContext.request.contextPath}/opers" method="GET"> <table border="1" width="50%"> <tr> <td>Id</td> <td>Name</td> <td>Surname</td> </tr> <c:forEach items="${Opers}" var="op"> <tr> <td>${op.id}</td> <td>${op.name}</td> <td>${op.surname}</td> </tr> </c:forEach> </table> </sf:form> </body> </html>
|
Контроллер
| Код | @Controller public class OperController { @Autowired private OperService operService; @RequestMapping(value = "/opers/{filialId}", method = RequestMethod.GET) public ModelAndView getOpers(@PathVariable("filialId") int filialId) { ModelAndView model = new ModelAndView("opers"); model.addObject("opers", operService.getOperByFilialId(filialId)); return model; } }
|
При вызове страницы из другой страницы
| Код | <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <form action="${pageContext.request.contextPath}/insert"> <table border="1" width="50%"> <tr> <th>Id</th> <th>Name</th> <th>Adress</th> <th></th> <th></th> </tr> <c:forEach items="${filials}" var="fil"> <tr> <td>${fil.id}</td> <td><a href="${pageContext.request.contextPath}/opers/${fil.id}">${fil.name}</a></td> <td>${fil.adress}</td> <td><a href="${pageContext.request.contextPath}/update/${fil.id}">Update</a></td> <td><a href="${pageContext.request.contextPath}/delete?id=${fil.id}">Delete</a></td> </tr> </c:forEach> </table> <input type="submit" value="insert" name="btnInsert" /> </form> </body> </html>
|
Мне не выводит данные которые связаны по внешнему ключу с другой таблицей, то есть контроллер не работает. Может я не совсем правильно выразился или может какие то данные не показал, вы скажите что еще добавить. |