我有一个接口和一个实现类:
界面
@RequestMapping(value = CUSTOMER_PATH + "{id}", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON + CHARSET_UTF_8_ENCODING})
Response getCustomerDetails(@PathVariable(CONTACT_ID) String id);
实施
@Override
public Response getCustomerDetails(String id) {
String methodname = "getCustomerDetails: ";
LOG.info(methodname + "Get Customer Details");
Response response;
System.out.println("******************id: " + id);
if (StringUtils.isEmpty(id)) {
response = Response.status(Status.BAD_REQUEST).entity(MockData.customerDetailsInvalid).build();
LOG.info(methodname + "Returning Customer's Details - Status: Invalid Request");
} else {
response = Response.status(Status.OK).entity(MockData.customerDetails).build();
LOG.info(methodname + "Returning Customer's Details - Status: OK");
}
return response;
}
路径 ..../MockDataProvider-war/services/mock/customers/ 7返回“无效请求”。id 的值打印为 null,即使它应该是 7。
有人知道为什么id为空吗?
通过从以下位置更改接口来修复它:
Response getCustomerDetails(@PathVariable(CONTACT_ID) String id);
至:
Response getCustomerDetails(String id);
和来自:
public Response getCustomerDetails(String id)
至
public Response getCustomerDetails(@PathVariable(CONTACT_ID) String id)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句