Adam Adam - 1 year ago 115
Java Question

How do I do date manipulation in SpEL?

How can I do date manipulation in the Spring Expression language?

<si:service-activator id="entryReader" expression="@blogEntryReader.getEntriesBetweenDates(payload.startDate, payload.startDate **PLUS 30 DAYS**)" input-channel="blogEntryReaderChannel"/>

Answer Source

Unfortunately, the java.util.Calendar doesn't have a builder API so it's not SpEL-friendly. One solution would be to use a helper class...

public static class CalendarManip {

    public static Date addDays(Date date, int days) {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_YEAR, 30);
        return cal.getTime();

Then, in SpEL...

T(foo.CalendarManip).addDays(payload.startDate, 30)

You could also use a <int-groovy:script/> if you don't want a helper class.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download