spring annotation for entity that links other enti

2019-08-30 03:19发布

I am writing calendar functionality into a spring mvc application. I have a calendar.jsp which provides a view of appointments, which in turn are associated with providers and customers.

My underlying MySQL database has tables for appointments, providers, and customers. But calendar is an abstraction for the user interface. The Calendar class does not have an associated table in the database, but the Calendar class does have a List of all appointments and a list of all providers, etc. I use @Entity annotation for appointments, providers, and customers.

What spring annotation should I use for the Calendar class?

I need to be able to reference calendar.providers and calendar.appointments, etc. from calendar.jsp.

Here is a link to an example of a similar class that uses Roo annotation.

I would prefer to avoid using Roo. It would be nice to be able to use the base spring framework distribution. My app uses Spring and Hibernate. I would like to avoid adding unnecessary complexity.

1条回答
男人必须洒脱
2楼-- · 2019-08-30 03:57

Maybe I've missed something here but are you sure you're not overcomplicating things? If you want to expose a populated Calendar instance in your jsp, then after populating it just add it to the model in your controller method.

Provided that Calendar has Java bean style properties for its providers and appointments then you can use dotted notation to access this data in the jsp.

For example, without seeing any controller code:

@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";
    }

    ...
}

And then in calendar.jsp:

<c:forEach var="appointment" items="${calendar.appointments}">
    <c:out value="${appointment.time}" /> <%-- Access the fields in the usual manner --%>
</c:forEach>
查看更多
登录 后发表回答