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