У меня есть небольшое приложение, использующее весенние весенние данные и angularJs, где я могу читать данные из своей таблицы и отображать их на своей странице. проблема I m new Я не знаю, как отобразить формат Hal Json, я знаю, как отображать простой Json формат, но нет Hal json. Я хочу получить json-файл как ответ, как показано ниже, спасибо за любую помощь. Потому что я хочу отображать как «id», так и «nom» со стола не только «nom».displayjson вместо hal json file
мой отдых:
RestResource:
package com.Benamar.dao;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import com.Benamar.entities.Categorie;
import com.Benamar.entities.Produit;
@RepositoryRestResource
public interface CategorieRepository extends JpaRepository<Categorie, Long>
{
}
index.html:
<body ng-app="MyApp">
<div id="categorie" ng-controller="CategController" >
<button ng-click="chargerCategories()" >Charger Cat</button>
<h1> Categorie</h1>
<div >
<table id="table-2">
<thead>
<tr>
<th>Id</th>
<th>Nom</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="c in categories._embedded.categories">
<td>{{c.id}}</td>
<td>{{c.nom}}</td>
</tr>
</tbody>
</table>
Угловые ЯШИ:
var app=angular.module("MyApp",[]);
app.controller("CategController",function($scope, $http){
$scope.categories=null;
$scope.chargerCategories=function(){
// get the values of table categories as json format (Rest findAll)
$http.get("http://localhost:8989/categories")
.then (function (success)
{
$scope.categories=success.data;
},
function(error){console.log="erreur !!!!"}
);
}
});
, когда я получаю категорию из базы данных, которые я получил это так:
{
"_embedded": {
"categories": [
{
"nom": "ordinateurs",
"_links": {
"self": {
"href": "http://localhost:8989/categories/1"
},
"categorie": {
"href": "http://localhost:8989/categories/1"
}
}
},
{
"nom": "tablets",
"_links": {
"self": {
"href": "http://localhost:8989/categories/2"
},
"categorie": {
"href": "http://localhost:8989/categories/2"
}
}
},
{
"nom": "telephones",
"_links": {
"self": {
"href": "http://localhost:8989/categories/3"
},
"categorie": {
"href": "http://localhost:8989/categories/3"
}
}
},
{
"nom": "calculatrices",
"_links": {
"self": {
"href": "http://localhost:8989/categories/4"
},
"categorie": {
"href": "http://localhost:8989/categories/4"
}
}
},
{
"nom": "tbi",
"_links": {
"self": {
"href": "http://localhost:8989/categories/5"
},
"categorie": {
"href": "http://localhost:8989/categories/5"
}
}
},
{
"nom": "readers",
"_links": {
"self": {
"href": "http://localhost:8989/categories/6"
},
"categorie": {
"href": "http://localhost:8989/categories/6"
}
}
},
{
"nom": "tv",
"_links": {
"self": {
"href": "http://localhost:8989/categories/7"
},
"categorie": {
"href": "http://localhost:8989/categories/7"
}
}
}
]
},
"_links": {
"self": {
"href": "http://localhost:8989/categories"
},
"profile": {
"href": "http://localhost:8989/profile/categories"
}
},
"page": {
"size": 20,
"totalElements": 7,
"totalPages": 1,
"number": 0
}
}
, но я хочу JSon файл, как это:
{
"content": [
{
"id": 1,
"nom": "ordinateurs",
},
{
"id": 2,
"nom": "tablets",
},
{
"id": 3,
"nom": "telephones",
},
{
"id": 4,
"nom": "cellulaires",
},
{
"id": 5,
"nom": "tbi",
},
{
"id": 6,
"nom": "readers",
},
{
"id": 7,
"nom": "tv",
}
]
}