0

I am using spring boot, spring v4.2.5

I am trying to pass a list of long.

My controller is :

@RequestMapping(value = "/rest/members/{memberId}/payments/{paymentsId}/process/{paymentMode}", method = RequestMethod.PUT)
public void processPayment(@PathVariable("memberId") Long memberId, @PathVariable("paymentsId") List<Long> paymentsId, @PathVariable("paymentMode") PaymentModeEnum paymentMode) {
    paymentService.processPayment(paymentsId, paymentMode);
}

Controller never gets called with this link.

http://localhost:8080/rest/members/6/payments/105,106/process/ATM

But it does with this

http://localhost:8080/rest/members/6/payments/105/process/ATM

Is it possible to pass a list of long?

Abdullah Khan
  • 12,010
  • 6
  • 65
  • 78
robert gagnon
  • 311
  • 1
  • 5
  • 14
  • 1
    Check out this answer http://stackoverflow.com/questions/9623258/passing-an-array-or-list-to-pathvariable-spring-java – Abdullah Khan May 23 '16 at 03:48

1 Answers1

0

Use the array of longs instead of the list and than simply convert it into a list if you need one.

@RequestMapping(value = "/rest/members/{memberId}/payments/{paymentsId}/process/{paymentMode}", method = RequestMethod.PUT)
public void processPayment(@PathVariable("memberId") Long memberId, @PathVariable("paymentsId") Long[] paymentsId, @PathVariable("paymentMode") PaymentModeEnum paymentMode) {
    paymentService.processPayment(Arrays.asList(paymentsId), paymentMode);
}
Daniel Olszewski
  • 13,995
  • 6
  • 58
  • 65