carlosgmercado
carlosgmercado

Reputation: 284

How to set a multiple parameters using String's Controller and RestTemplate?

Hi I need to modify an existent Rest interface. The old Rest interface only take a phone number then look for a record. The phone number used to be unique with the table. Now is the combination of the phone and a number (batchid). So i need to modify the service impl and the client that calls it. Here is the old controller:

@RequestMapping(value="/{phone}", method = RequestMethod.GET)
        @ResponseBody
        public BatchDetail  findByPhone(@PathVariable String phone) {
            return batchDetailService.findByPhone(phone);

        }

and here is the how the old client is accesing it:

private static final String URL_GET_BATCHDETAIL_PHONE = "http://localhost:8080/Web2Ivr/restful/batchdetail/{phone}";
batchdetail = restTemplate.getForObject(URL_GET_BATCHDETAIL_PHONE, BatchDetail.class, phone);           
batchdetail.setStatus("OK");
restTemplate.put(URL_TO_UPDATE_BATCHDETAIL, batchdetail, batchdetail.getId())

;

So my question will be how to modify the controller and the restemplate's client call to support two variables, phone and the number(batchid) something like:

http://localhost:8080/Web2Ivr/restful/batchdetail/{batchid}/{phone}

Upvotes: 2

Views: 1278

Answers (1)

dardo
dardo

Reputation: 4960

@RequestMapping(value="/{batchid}/{phone}", method = RequestMethod.GET)
@ResponseBody
public BatchDetail  findByPhone(@PathVariable String phone, @PathVariable String batchid) {
    return batchDetailService.findByPhone(phone);

}

Upvotes: 1

Related Questions