所以我的 Angular 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;
});
});
和我的休息 Controller
@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>
关于javascript - AngularJs Controller 获取请求未命中 Spring MVC Rest 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26983724/