이해를 도와주세요. 다 모두 잘하지만 한 가지 방법이 작동되지 않고, 내가 몇 요청스프링 MVC 아약스 DELETE 메소드 404 오류
이 나는 404 오류가function deleteFunc(id) {
$.ajax({
dataType: "json",
type: "DELETE",
url: "/BookList.vw/" + id,
async: true,
success: function (response) {
},
error: function (e) {
alert("Book doesn't found");
}
});
}
function modifyFunc(id) {
alert(id);
$.ajax({
dataType: "json",
type: "PUT",
url: "/EditBook.vw",
data: id,
success: function (response) {
},
error: function (e) {
alert('Server problems. You cannot modify this book.');
}
});
}
컨트롤러 :
@Controller
@RequestMapping("/BookList.vw")
public class BookListController {
@Autowired
private IBookService bookService;
public String getModelName() {
return "BookList";
}
public BookListController() {
}
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView openMain(Model m) throws Exception {
m.addAttribute("book", new Book());
Map<String, Object> model = new HashMap<String, Object>();
List<Book> books = bookService.listBooks();
model.put("books", books);
return new ModelAndView(getModelName(), "model", model);
}
@RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
public ModelAndView delete(@PathVariable int id) throws Exception {
bookService.removeBook(id);
return new ModelAndView(getModelName());
}
@RequestMapping(method = RequestMethod.POST)
public ModelAndView search(@ModelAttribute Book b) throws Exception {
List<Book> books = bookService.searchBook(b.getName().trim());
Map<String, Object> model = new HashMap<String, Object>();
model.put("books", books);
return new ModelAndView("BookList", "model", model);
}
}
검색 및 주요 방법 작품 좋은,하지만 난 나는이 같은 DELETE 방법에 오류가 이유를 이해할 수 없다 :
"NetworkError: 404 Not Found - http://localhost:8080/BookList.vw/2"
URL이 맞습니다. 다른 부분은 완벽한 작업입니다. –