Linkto cast issue in spring HATEOAS

887 Views Asked by At

When I try to form the link like below.

Link userLink = linkTo((controllerClass).slash("?location="+location+"&scheduledDepartur="+scheduleDepatur).withRel(USER_REL));

and it shows error as

The method slash(String) is undefined for the type Class<TrainController>

When try to use below link method I got

Link selfLink = linkTo(methodOn(controllerClass).getOffTrains(trainStatus, valid, locale).slash("?depatureLocation="+depatureLocation+"&scheduledDepartureDate="+scheduleDepatureDate).withSelfRel());

got below error

The method slash(String) is undefined for the type HttpEntity<TrainStatus>.

Help me to resolve this issue.

1

There are 1 best solutions below

0
On

all your parenthesis are off.

Link selfLink = linkTo(methodOn(controllerClass).getOffTrains(trainStatus, valid, locale).slash("?depatureLocation="+depatureLocation+"&scheduledDepartureDate="+scheduleDepatureDate).withSelfRel());

should be

Link selfLink = linkTo(methodOn(controllerClass).getOffTrains(trainStatus, valid, locale)).slash("?depatureLocation="+depatureLocation+"&scheduledDepartureDate="+scheduleDepatureDate).withSelfRel());

I'm surprised those query string parameters you have aren't methods on the getOffTrains controller method..then it would just work for you.