java - 在Web服务API中传递参数

标签 java web-services rest spring-mvc

我是网络服务新手,目前可以通过调用 https://localhost/application/service/v1.0/contacts/account= 来运行我的查询{帐户ID} 我想让我的网址看起来像 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; 
  } 

}

最佳答案

这很简单,试试这个:

@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; 
  } 

}

关于java - 在Web服务API中传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38340981/

相关文章:

java - 图论 : Find the Jordan center?

java - 网络服务测试

api - Swagger api 列表为空

java - 在 REST 调用上使 Java 服务器保持 DCOM 对象处于 Activity 状态

xml - 如何使用 Axis2 和 Rampart 在 SOAP 请求中添加 MessageID

java - Resteasy 客户端抛出异常

java - 依赖域约束进行验证是一个好习惯吗

java - 使用 Metro 的 Ws-Security header

java - 如何将值为Lists的Map序列化为JSON?

.net - 选择什么? .net 3.5 中的 ASMX Web 服务或 WCF?