2013-08-23 134 views
0

我定義了一個$資源,並添加補丁方法:

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) { 
} 

回答

0

我通過添加Content-Type表頭來修復它:

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

它的作品,但它是正確的方式?