[英]There was an unexpected error (type=Method Not Allowed, status=405). Request method 'POST' not supported
[英]There was an unexpected error (type=Method Not Allowed, status=405). Request method 'GET' not supported with spring boot
我正在嘗試使用 Spring 引導、reactjs 和 Z38C3787939C7B28B8FCE7DCE7D7D7D7D1D07A33Z 和 Spring 創建刪除 function。 第一步,我只是通過直接輸入 URL 來確認是否激活了刪除操作。 但是即使我直接輸入 URL 也不起作用。 我知道 GET 不受支持,但我不知道應該修復哪個。 如果你知道,請告訴我。
動作控制器.java
package com.example.demo.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.demo.repository.CheckListRepository;
import com.example.demo.service.CheckListService;
@CrossOrigin
@RequestMapping("action/")
@RestController
public class ActionController {
@Autowired
CheckListRepository clr;
@Autowired
CheckListService cls;
@DeleteMapping(path = "{deleteId}")
public void deleteAction(@PathVariable Integer deleteId) {
clr.deletebyListNo(deleteId);
}
}
PS:這是關於內容的 axios 代碼。 Controller
package com.example.demo.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.demo.entity.CheckList;
import com.example.demo.entity.CheckListForm;
import com.example.demo.repository.CheckListRepository;
import com.example.demo.service.CheckListService;
@CrossOrigin
@RestController
@RequestMapping("api/")
public class CheckListController {
@Autowired
private CheckListRepository checkListRepository;
@Autowired
private CheckListService cls;
@GetMapping("list")
public List<CheckListForm> getList() {
List<CheckList> checkList = this.checkListRepository.findAll();
List<CheckListForm> checkListForm = cls.entityToForm(checkList);
return checkListForm;
}
}
CheckList.js
import axios from 'axios'
const CHECKLIST_REST_API_URL = 'http://localhost:8080/api/list';
class CheckListService {
getList() {
return axios.get(CHECKLIST_REST_API_URL);
}
}
export default new CheckListService();
我可以通過以下方式確認控件中的刪除操作方法已激活。 我改變了代碼
package com.example.demo.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.demo.repository.CheckListRepository;
import com.example.demo.service.CheckListService;
@CrossOrigin
@RequestMapping("action/")
@RestController
public class ActionController {
@Autowired
CheckListRepository clr;
@Autowired
CheckListService cls;
@DeleteMapping(path = "{deleteId}")
public void deleteAction(@PathVariable Integer deleteId) {
clr.deletebyListNo(deleteId);
}
}
至
package com.example.demo.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.demo.repository.CheckListRepository;
import com.example.demo.service.CheckListService;
@CrossOrigin
@RequestMapping("action/")
@RestController
public class ActionController {
@Autowired
CheckListRepository clr;
@Autowired
CheckListService cls;
@RequestMapping(path = "{deleteId}")
public void deleteAction(@PathVariable Integer deleteId) {
clr.deletebyListNo(deleteId);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.