0

我定义了一个 $resource 并添加了一个 PATCH 方法:

myapp.factory( 'Monitoring', function($resource) {
   return $resource('/webapp/network/v1/cronjobs/:id/:action', { id: '@id' }, {
       status: { method: 'PATCH', params:{id:"@id", action: 'status'}}
   }
   );
});

调用我得到的 URL 时PATCH http://localhost:8080/webapp/network/v1/cronjobs/1/status 415 (Unsupported Media Type)

    changeStatus: function(id, status) {
        var m = new Monitoring({id:id});
        m.status = status;
        m.$status();
    }

我的后端是春天

@RequestMapping(value = "/{id}/status", method = RequestMethod.PATCH)
public ResponseEntity<Void> patchStatus(@PathVariable("id") Long id,
        @RequestBody String status) {
}
4

1 回答 1

0

Content-Type我通过添加标题来修复它:

status: { method: 'PATCH', headers:{'Content-Type': 'application/json'}, params:{id:"@id", action: 'status'}}

它有效,但它是正确的方法吗?

于 2013-08-24T05:47:41.820 回答