[英]AngularJs controller get request not hitting Spring MVC Rest Service
所以我有我的角度javascript
var app = angular.module('app', []);
app.controller('controller', function($scope, $http) {
$http.get('http://localhost:8080/core/students.json')
.success(function(data) {
$scope.user = data;
});
});
和我的休息控制器
@RestController
public class StudentRestController {
@RequestMapping(value = "/students", produces = { "application/json" }, method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public Student getStudent() {
// return studentService.getStudentByUserName(userName);
Student s = new Student();
s.setUserName("userName");
s.setEmailAddress("email");
return s;
}
}
但是由于某种原因,javascript ajax请求没有达到getStudent()方法。 为什么是这样? 我收到控制台错误
"GET http://localhost:8080/core/students.json 404 (Not Found)"
普通按钮url调用按预期工作
将angularjs应用更改为
var app = angular.module('app', []);
app.controller('controller', [ "$scope", "$http", function($scope, $http) {
$http.get("http://localhost:8080/students").success(function(data) {
$scope.user = data;
});
} ]);
如果您的web.xml
<servlet-mapping>
<servlet-name> dispatcherServlet </servlet-name>
<url-pattern> * </url-pattern>
</servlet-mapping>
您在@RequestMapping上定义“ / students”,那么您的URL应为“ ... / core / students”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.