【问题标题】:How to show list of Products coming from spring rest webservice on html page如何在html页面上显示来自spring rest webservice的产品列表
【发布时间】:2017-09-01 07:53:50
【问题描述】:

我使用 spring boot、spring-data 创建了一个 spring RESTFul Web 服务。 此 url(/api/products) 以 json 格式返回产品对象列表。

这是我所有用于存储库和控制器的 Spring 数据休息服务代码

@RepositoryRestResource
public interface ProductRepository extends PagingAndSortingRepository<Product, Long> {
}

下面是json响应

products: [ 

    {
    description: "some product 1",
    price: 100,
    imageUrl: "image url",
    _links: {
    self: {
    href: "http://localhost:8080/products/1"
    },
    product: {
    href: "http://localhost:8080/products/1"
    }
    }
    },
    {
    description: "some product 2",
    price: 200,
    imageUrl: "image url",
    _links: {
    self: {
    href: "http://localhost:8080/products/2"
    },
    product: {
    href: "http://localhost:8080/products/2"
    }
    }
    }
    ]

问。如何在客户端使用这个休息路径并以表格格式显示在html页面上?

【问题讨论】:

  • 你的前端是什么内置的?
  • 还没有构建,我想学习如何消费并在html页面上显示。
  • 有点取决于您在前端使用什么。它成为 html 的机会很小,因为 html 不是动态的。最有可能的是,您将使用 jsp、jsf、angular、...
  • 您可以通过 ajax 接收 json 作为响应,并通过 jquery 将其映射到 html 表。您可以询问是否需要代码示例
  • 是的代码示例

标签: java web-services spring-data spring-rest


【解决方案1】:

我是用 jquery ajax 做的,数据表也用 bootstrap 给了一些漂亮的外观

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-10
    • 1970-01-01
    • 2022-08-16
    相关资源
    最近更新 更多