Jhipsterを使用して自分のコードを生成します。角オブジェクトのリストへのアクセス方法(Java Restで取得)
イベントのリストを持つカレンダークラスがあります。 私の角度コントローラ/ビュー内のイベントリストにアクセスしたいです。 クエリJava Restでオブジェクト・カレンダーにアクセスできます。 しかし、calendar.eventsは定義されていません。リストに直接アクセスすることはできません。
コントローラ内のイベントリストの宣言方法は?
のJavaパーツ: Calendar.java
@OneToMany(mappedBy = "calendar", cascade = { CascadeType.ALL }, orphanRemoval = true)
@JsonIgnore
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<Event> events = new HashSet<>();
Event.java
@ManyToOne
private Calendar calendar;
CalendarResource.java
@RequestMapping(value = "/calendars/{id}",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
@Transactional(propagation=Propagation.REQUIRED)
public ResponseEntity<Calendar> getCalendar(@PathVariable Long id) {
log.debug("REST request to get Calendar : {}", id);
Calendar calendar = calendarRepository.findOne(id);
return Optional.ofNullable(calendar)
.map(result -> new ResponseEntity<>(
result,
HttpStatus.OK))
.orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
}
@RequestMapping(value = "/calendars",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
@Transactional(propagation=Propagation.REQUIRED)
public ResponseEntity<List<Calendar>> getAllCalendars(Pageable pageable)
throws URISyntaxException {
log.debug("REST request to get a page of Calendars");
Page<Calendar> page = calendarRepository.findAll(pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/calendars");
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
角部 calendar.service.js
(function() {
'use strict';
angular
.module('mandefaApp')
.factory('Calendar', Calendar);
Calendar.$inject = ['$resource'];
function Calendar ($resource) {
var resourceUrl = 'api/calendars/:id';
return $resource(resourceUrl, {}, {
'query': { method: 'GET', isArray: true},
'get': {
method: 'GET',
transformResponse: function (data) {
if (data) {
data = angular.fromJson(data);
}
return data;
}
},
'update': { method:'PUT' }
});
}
})();
calendar.controller.js
(function() {
'use strict';
angular
.module('mandefaApp')
.controller('CalendarController', CalendarController);
CalendarController.$inject = ['$scope', '$state', 'Calendar', 'CalendarSearch', 'ParseLinks', 'AlertService', 'pagingParams', 'paginationConstants'];
function CalendarController ($scope, $state, Calendar, CalendarSearch, ParseLinks, AlertService, pagingParams, paginationConstants) {
var vm = this;
vm.loadPage = loadPage;
vm.predicate = pagingParams.predicate;
vm.reverse = pagingParams.ascending;
vm.transition = transition;
vm.itemsPerPage = paginationConstants.itemsPerPage;
vm.clear = clear;
vm.search = search;
vm.loadAll = loadAll;
vm.searchQuery = pagingParams.search;
vm.currentSearch = pagingParams.search;
loadAll();
function loadAll() {
if (pagingParams.search) {
CalendarSearch.query({
query: pagingParams.search,
page: pagingParams.page - 1,
size: vm.itemsPerPage,
sort: sort()
}, onSuccess, onError);
} else {
Calendar.query({
page: pagingParams.page - 1,
size: vm.itemsPerPage,
sort: sort()
}, onSuccess, onError);
}
function sort() {
var result = [vm.predicate + ',' + (vm.reverse ? 'asc' : 'desc')];
if (vm.predicate !== 'id') {
result.push('id');
}
return result;
}
function onSuccess(data, headers) {
vm.links = ParseLinks.parse(headers('link'));
vm.totalItems = headers('X-Total-Count');
vm.queryCount = vm.totalItems;
vm.calendars = data;
vm.page = pagingParams.page;
}
function onError(error) {
AlertService.error(error.data.message);
}
}
function loadPage (page) {
vm.page = page;
vm.transition();
}
function transition() {
$state.transitionTo($state.$current, {
page: vm.page,
sort: vm.predicate + ',' + (vm.reverse ? 'asc' : 'desc'),
search: vm.currentSearch
});
}
function search (searchQuery) {
if (!searchQuery){
return vm.clear();
}
vm.links = null;
vm.page = 1;
vm.predicate = '_score';
vm.reverse = false;
vm.currentSearch = searchQuery;
vm.transition();
}
function clear() {
vm.links = null;
vm.page = 1;
vm.predicate = 'id';
vm.reverse = true;
vm.currentSearch = null;
vm.transition();
}
}
})();
HTMLコード:
<div class="table-responsive">
<table class="jh-table table table-striped">
<thead>
<tr jh-sort="vm.predicate" ascending="vm.reverse" callback="vm.transition()">
<th jh-sort-by="id"><span translate="global.field.id">ID</span> <span class="glyphicon glyphicon-sort"></span></th>
<th jh-sort-by="title"><span translate="mandefaApp.calendar.title">Title</span> <span class="glyphicon glyphicon-sort"></span></th>
<th jh-sort-by="title">Event Size <span class="glyphicon glyphicon-sort"></span></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="calendar in vm.calendars track by calendar.id">
<td><a ui-sref="calendar-detail({id:calendar.id})">{{calendar.id}}</a></td>
<td>{{calendar.title}}</td>
<td>{{calendar.events.lenght}}</td> <!-- How can access to events in calendar object ? -->
</tr>
</tbody>
</table>
</div>