0
Restriction getList()メソッドを使用する私の工場では、バックエンド側の操作を処理するスプリングコントローラのデータベースからレコードを取得しても、空の配列を返します。私はこの問題の原因がアプリケーションのJava側か角側にあるのかどうかはわかりません。なぜこうなった?Restart getList()は空の配列を返します
FlightController.java
package regularmike.airline.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import regularmike.airline.entity.Flight;
import regularmike.airline.service.FlightService;
@RestController
@RequestMapping("/flight")
public class FlightController {
@Autowired
FlightService flightService;
@RequestMapping(value = "/getFlights", method = RequestMethod.GET, produces = "application/json")
public List<Flight> getAllFlights() {
List<Flight> allFlights = flightService.getAllFlights();
return allFlights;
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json")
public Flight getSeats(@PathVariable long id) {
Flight result = flightService.getByFlightid(id);
return result;
}
}
FlightFactory.js
(function() {
'use strict'
angular.module('airline').factory('FlightFactory', FlightFactory);
function FlightFactory(Restangular) {
function getAllFlights() {
return Restangular.all('flight/getFlights').getList();
}
return {
getAllFlights: getAllFlights
};
}
})();
DashboardController.js
(function() {
'use strict'
angular.module('airline').controller('DashboardController', ['FlightFactory', DashboardController]);
function DashboardController(FlightFactory) {
var dashCtrl = this;
FlightFactory
.getAllFlights()
.then(getFlights)
function getFlights(response)
{
dashCtrl.flights = response;
console.log(dashCtrl.flights);
}
}
})();
config.jsの
(function() {
angular.module('airline').config(
[ 'RestangularProvider', restangularConfig ]);
function restangularConfig(RestangularProvider) {
RestangularProvider.setBaseUrl('/');
RestangularProvider.setDefaultHeaders(
{"Accept": 'application/json'},
{"Content-Type": "application/json+hal"});
RestangularProvider.setResponseInterceptor(function (data, operation, what) {
var resp;
if (operation === 'get') {
if (_.has(data, '_embedded')) {
resp = data._embedded;
} else {
resp = data;
}
if (_.has(data, '_links')) {
resp._links = data._links;
}
return resp;
}
if (operation === 'getList') {
if (_.has(data, '_embedded')) {
resp = data._embedded[what];
} else {
resp = [];
}
if (_.has(data, '_links')) {
resp._links = data._links;
}
return resp;
}
return data;
});
RestangularProvider.setRequestInterceptor(function (element, operation, route, url) {
if (operation === 'put' || operation === 'post') {
if (angular.isDefined(element._links)) {
element._links.self.href = element._links.self.href.split('{?projection}')[0];
}
return element;
}
});
RestangularProvider.setRestangularFields({
selfLink: '_links.self.href'
});
}
})();