我需要在java类中调用index()
方法。但我试过这种方式,它不工作。AnjularJs与Spring启动集成
controller.js
的console.log('coming here....');
正在上升,此后http路径无法识别。
@RestController
public class DatumBoxShedule {
@Autowired
private DatumService datumService;
@RequestMapping(value = "/loadIndex", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
public String index() throws IOException {
}
}
controller.js
app.controller('datumBoxShedule', function($scope, $http) {
$scope.newTodo = {};
$scope.loadIndex = function(){
console.log('coming here....');
$http.get('loadIndex')
.success(function(data, status, headers, config) {
$scope.todos = data;
})
.error(function(data, status, headers, config) {
alert('Error loading DatumBoxShedule');
});
};
$scope.loadIndex();
});
尝试检查状态码,它很可能是404,这意味着您需要提供绝对路径:'$ http.get('/ loadIndex')...'。您可以直接从浏览器访问Rest API端点,或使用Postman等浏览器扩展来检查请求/响应。 – sm4
我试过$ http.get('/ loadIndex'),但仍然出现同样的错误。 – WPS
哪个后端REST服务的基础上下文?通常你会有'http:// host:port/* myApp */loadIndex' –