我正在将日历功能写入 Spring MVC 应用程序中。我有一个calendar.jsp
,它提供了约会
的 View ,而约会又与providers
和customers
相关联。
我的底层 MySQL 数据库包含约会
、提供商
和客户
表。但日历是用户界面的抽象。 Calendar
类在数据库中没有关联的表,但 Calendar
类确实有一个包含所有约会
的List
code> 和所有 providers
的 list
等。我使用 @Entity
注释进行约会
,提供商
和客户
。
我应该为 Calendar
类使用什么 spring 注释?
我需要能够从 calendar.jsp
引用 calendar.providers
和 calendar.appointments
等。
这里是a link to an example of a similar class that uses Roo annotation 。
我宁愿避免使用 Roo。如果能够使用基本的 spring 框架发行版那就太好了。我的应用程序使用 Spring 和 Hibernate。我想避免增加不必要的复杂性。
最佳答案
也许我在这里错过了一些东西,但你确定你没有让事情变得过于复杂吗?如果您想在 jsp 中公开填充的 Calendar
实例,那么在填充它之后,只需将其添加到 Controller 方法中的模型中即可。
如果 Calendar
具有其 providers
和 appointments
的 Java bean 样式属性,那么您可以使用点分符号在 jsp 中访问此数据.
例如,没有看到任何 Controller 代码:
@Controller
public class SomeController {
@RequestMapping("/calendar")
public String showCalendar(Model model) {
Calendar calendar = getCalendar() // Or whatever you do to create it
model.addAttribute("calendar", calendar);
return "calendar";
}
...
}
然后在calendar.jsp中:
<c:forEach var="appointment" items="${calendar.appointments}">
<c:out value="${appointment.time}" /> <%-- Access the fields in the usual manner --%>
</c:forEach>
关于java - 链接其他实体的实体的 spring 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21592892/