0
私はテーブルからデータを読み込んでページに表示できるSpringブートスプリングデータとangularJsを使用する小さなアプリケーションを持っています。 問題は私は新しい私はHal Json形式を表示する方法を知っていない、私はシンプルなJson形式を表示する方法を知っているが、ではないHal json。私は、以下のような応答としてjsonファイルを取得したいと思います。 「id」と「nom」の両方を表から「nom」だけでなく表示したいからです。haljsonファイルの代わりにdisplayjson
私の休息:
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>
の
角度JS:私は、データベースからカテゴリを取得するときに
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",
}
]
}