2016-07-13 96 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