2016-07-13 19 views
0

ich an einen Web Service neu bin und derzeit in der Lage meine Abfrage auszuführen durch den Aufruf https://localhost/application/service/v1.0/contacts/account= {accountId} Ich möchte meine URL wie aussehen https://localhost/application/service/v1.0/contacts?account= {accountId}vorbei Parameter in Webservice API

Darf ich wissen, wie dies zu erreichen nicht mit QueryParam? Ich arbeite im Frühjahr mvc

@Controller 
public class ContactListResponseController extends BaseWebServiceController 
{ 

public static final String PATH = "/v" + VERSION + "/contacts/account={accountId}"; 

@Autowired 
private ContactService contactService; 

@RequestMapping(value = PATH, method = RequestMethod.GET) 
@ResponseBody 
public ContactListResponseBean doGetMyAssignedAccounts (@PathVariable String accountId, 
                 HttpServletRequest request, 
                 HttpSession session, 
                 HttpServletResponse response, 
                  @ModelAttribute(User.USER_REQUEST_VAR) User user) 
    throws Exception 
    { 

    List<ContactSummaryWebServiceBean> contactList = contactService.getContactsListForCallPointWebService(accountId); 
    ContactListResponseBean result = new ContactListResponseBean(contactList); 
    return result; 
    } 

} 

Antwort

2

Es ist eine einfache Sache, versuchen Sie dies:

@Controller 
public class ContactListResponseController extends BaseWebServiceController 
{ 

public static final String PATH = "/v" + VERSION + "/contacts"; 

@Autowired 
private ContactService contactService; 

@RequestMapping(value = PATH, method = RequestMethod.GET) 
@ResponseBody 
public ContactListResponseBean doGetMyAssignedAccounts (@RequestParam("account") String accountId, 
                 HttpServletRequest request, 
                 HttpSession session, 
                 HttpServletResponse response, 
                  @ModelAttribute(User.USER_REQUEST_VAR) User user) 
    throws Exception 
    { 

    List<ContactSummaryWebServiceBean> contactList = contactService.getContactsListForCallPointWebService(accountId); 
    ContactListResponseBean result = new ContactListResponseBean(contactList); 
    return result; 
    } 

} 
+0

Könnten Sie bitte diesen Controller Check debuggen, wenn die 'accountId' Setup war mit 2465543400 ? Und vergiss nicht, dass ich deinen Code an zwei Stellen geändert habe. – Blank

+0

Es hat funktioniert. ein Problem war mit ID. Vielen Dank – ronypatil

0

Diese Probe.

@RequestMapping("/pets/{petId}") 
public void findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) { 
    // implementation omitted 
} 

Ihr Code.

@Controller 
public class ContactListResponseController extends BaseWebServiceController 
{ 

    public static final String PATH = "/v" + VERSION + "/contacts/{accountId}"; 

    @Autowired 
    private ContactService contactService; 

    @RequestMapping(value = PATH, method = RequestMethod.GET) 
    @ResponseBody 
    public ContactListResponseBean doGetMyAssignedAccounts (@PathVariable String accountId, 
                 HttpServletRequest request, 
                 HttpSession session, 
                 HttpServletResponse response, 
                  @ModelAttribute(User.USER_REQUEST_VAR) User user) 
    throws Exception 
    { 

     List<ContactSummaryWebServiceBean> contactList = contactService.getContactsListForCallPointWebService(accountId); 
     ContactListResponseBean result = new ContactListResponseBean(contactList); 
     return result; 
    } 

} 

url Ajax = "/ v" + VERSION + "/ Kontakte /" + accountId,

: D

+0

Danke Kumpel, aber ich suche nach URL wie folgt https: //localhost/application/service/v1.0/contacts? Account = {accountid} – ronypatil