我正在使用AngularJS从我的控制器发送POST请求,我收到此错误:
不支持POST
JS函数如下:
addUserDetails: function(addUser) {
alert("M into add user function in service");
return restClientTemplate.execute({
method: 'POST',
url: 'json/user-add',
data: addUser
});
}
我的Java Spring Controller如下:
@Controller
public class AddUserController {
@Resource
private Settings settings;
@Resource
private RestOperations rest;
private static final String ORGANIZATION_URL_KEY = "configuration.organization.service.endpointUrl";
private static final String ORG_PRODUCT_LIST_URL_KEY = "configuration.org.product.list.service.endpointUrl";
@RequestMapping(value = "/json/user-add", method = RequestMethod.POST, produces = "application/json")
public ServiceResponse addOrganization(@RequestBody SaveOrganizationForm request) {
System.out.println("M into controllerrrr");
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode requestBody = objectMapper.createObjectNode();
populateRequestObject(request, objectMapper, requestBody);
String url = MessageUtil.format(settings.getString(ORGANIZATION_URL_KEY) + "/s2");
ServiceResponse response = rest
.exchange(url, HttpMethod.POST, new HttpEntity<>(requestBody), ServiceResponse.class).getBody();
return response;
}