gpt4 book ai didi

javascript - AngularJs Controller 获取请求未命中 Spring MVC Rest 服务

转载 作者:行者123 更新时间:2023-12-03 11:24:28 25 4
gpt4 key购买 nike

所以我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com