2016-07-13 97 views
0

我在web服務新的,目前能夠通過調用運行我的查詢https://localhost/application/service/v1.0/contacts/account= {帳戶ID} 我想讓我的URL看起來像https://localhost/application/service/v1.0/contacts?account= {帳戶ID}參數傳遞

可我知道如何做到這一點不使用QueryParam?我在Spring 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; 
    } 

} 

回答

2

這是一個簡單的事情工作,試試這個:

@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

可否請你調試這個控制器檢查,如果'accountId'是建立與2465543400 ?別忘了我已經在兩個地方更改了你的代碼。 – Blank

+0

它的工作。一些問題是與ID。非常感謝 – ronypatil

0

此示例。

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

您的代碼。

@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 = 「/ V」 +版本+ 「/聯繫人/」 +帳戶ID,

:d

+0

感謝兄弟,但我正在尋找這樣的URL:https://localhost/application/service/v1.0/contacts?account = {accountid} – ronypatil