我的控制器支持:'刪除' 方法不使用Spring
@RequestMapping(value = "/list/{fn}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody ResponseEntity<Record> deleteUser(@PathVariable("fn") String filename) {
System.out.println("Fetching & Deleting data " + filename);
Record user1 = rep.findByfilename(filename);
if (user1 == null) {
System.out.println("Unable to delete." + filename + " not found");
return new ResponseEntity<Record>(HttpStatus.NOT_FOUND);
}
rep.deleteByfilename(filename);
return new ResponseEntity<Record>(HttpStatus.NO_CONTENT);
}
}
我的js代碼:
$scope.del = function (record) {
if (confirm('Do you really want to delete?')){
$http['delete']('/camera/list/' + record.filename).then(function() {
$scope.records.splice($scope.records.indexOf(record), 1);
});
}
};
我的訪問設置:
http
.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.antMatchers("/imageview", "/hello").access("hasRole('USER')")
.antMatchers("/camera/list").permitAll()
.antMatchers("/camera/store").permitAll()
.antMatchers("/camera/list/{fn}").permitAll()
.antMatchers("/imageview2", "/hello2").access("hasRole('ADMIN')").and()
.formLogin().and().exceptionHandling()
.accessDeniedPage("/access-denied");
http
.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login").permitAll()
.and()
.logout()
.permitAll();
}
錯誤我得到是:
DELETE
XHR
http://localhost:8086/camera/list/a0c8918e4b088de4a5c7796e3eb11229 [HTTP/1.1 405 Method Not Allowed 22ms]
起初,我的刪除函數可以工作,但是在我使用spring security之後,我得到了這個不支持的錯誤。任何人都可以幫忙?我嘗試在網上尋求幫助,但沒有解決方案。
我沒有web.xml文件 –
然後在你的類中實現WebApplicationInitializer – Alexander
創建另一個新類的權利? –