我在 MacOSX Maverick 上使用 JHipster 0.13 和 JDK 1.7.0.55。到目前为止一切正常。
我的问题是我已经生成了一个新实体,并且可以在一些修改后添加新实体。但是当我点击删除按钮时,前端没有任何反应。在 Chrome 的控制台中,我得到
DELETE http://0.0.0.0:9000/app/rest/products?productId=1 405 (Method Not Allowed) angular.js:8081
XHR finished loading: DELETE "http://0.0.0.0:9000/app/rest/products?productId=1".
后端记录消息:
[WARN] org.springframework.web.servlet.PageNotFound - Request method 'DELETE' not supported
删除方法已经由生成器定义,据我了解,它应该可以工作。
我需要检查/修改其他任何地方以使其正常工作吗?
在 AngularJS 中已经定义了这个 service.js:
myapp.factory('Product', ['$resource',
function ($resource) {
return $resource('app/rest/products/:id', {}, {
'query': { method: 'GET', isArray: true},
'get': { method: 'GET'},
'delete': {method: 'DELETE'}
});
}]);
在Java方面我有:
/**
* DELETE /rest/products/:id -> delete the "id" product.
*/
@RequestMapping(value = "/rest/products/{id}",
method = RequestMethod.DELETE,
produces = "application/json")
@Timed
public void delete(@PathVariable Long id, HttpServletResponse response) {
log.debug("REST request to delete Product : {}", id);
productRepository.delete(id);
}
那是在具有添加和保存方法的同一个类中,这是有效的。