저는 AngularJS를 통해 스프링 컨트롤러에 양식 데이터를 전달하는 간단한 코드를 가지고 있습니다. 크롬 디버거에서는 올바른 값이 요청과 함께 전달되는 것을 볼 수 있지만 405 (Request method 'POST' not supported)
과 디버그 포인터가 내 컨트롤러에 충돌하지 않는다는 오류가 발생합니다. 그래서 이것은 내 POST 요청이 내 컨트롤러에 매핑되지 않았기 때문에 발생하는 것으로 알고 있지만 올바르게 처리했습니다.Spring - 405 (요청 방법 ' POST '은 지원되지 않습니다.)
형태 : -
<form name="empForm" ng-controller="insertEmpCtrl" ng-submit="insertEmp()">
<table>
<tr><td>First name: <input type="text" class="form-control" name="fname" ng-model="formData.fname"/></td></tr>
<tr><td>Last name: <input type="text" class="form-control" name="lname" ng-model="formData.lname"/></td></tr>
<tr><td>Contact no: <input type="text" class="form-control" name="contact" ng-model="formData.contactno"/></td></tr>
<tr>
<td><input type="submit" value="Save" /> <input type="reset" value="Edit"></td>
<td></td>
</tr>
</table>
AngularJS와 컨트롤러 : -
empApp.controller('insertEmpCtrl',function($scope,$http){
$scope.insertEmp = function(){
$http.post("http://localhost:8080/IdeaOne#/addemp", $scope.formData, {
withCredentials: true,
headers: {'Content-Type': 'application/json'},
transformRequest: angular.identity
}).success(function(){console.log("done")}).error(function(){console.log("error")});
};
});
봄 컨트롤러 : -
public class HelloController {
@RequestMapping(method = RequestMethod.GET)
public String home(ModelMap model){
return "hello";
}
//method redirects to hello.jsp
@RequestMapping(value="/addemp",method = RequestMethod.POST)
public String addEmployee(@RequestBody Employee employee) {
EmployeeManager.empDB.add(employee);
return "hello";
}
//method returns a link list as a json doc to the front end
@RequestMapping(value="/viewall",method = RequestMethod.GET)
public @ResponseBody
LinkedList<Employee> viewAll(ModelMap model){
return EmployeeManager.viewEmployees();
}
}
,어디에서 잘못 됐는지 알아낼 수있는 사람이 있습니까? 스프링 컨트롤러
@RequestMapping(value="/addemp",method = RequestMethod.POST)
에
1.'@ Controller'를 컨트롤러에 포함 시켰습니까? 2.'form'에서'action'을 사용하지 않으시겠습니까? – jhyap
크롬 콘솔을 확인하고 방문한 URL을 확인하십시오. – geoand
value = "/ addemp"는 값 = "IdeaOne #/addemp"이어야합니다. –