gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 03:29:06 25 4
gpt4 key购买 nike

我是网络服务新手,目前可以通过调用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com