【问题标题】:How to generate form and crud using Spring and React如何使用 Spring 和 React 生成表单和 crud
【发布时间】:2017-01-11 06:13:50
【问题描述】:

我想根据我的 API 动态生成 crud 表单。

我正在使用 spring、spring-data-rest 和 spring-hateoas。

我不想从 java 中渲染 react。

我正在考虑调整 /profile 并添加一些元信息来呈现我的表单。

有人对我有实施建议吗?

我看到一些 react 项目与我需要的客户端类似,但它不适用于 spring:

https://github.com/mozilla-services/react-jsonschema-form

【问题讨论】:

    标签: spring reactjs spring-data spring-data-rest spring-hateoas


    【解决方案1】:

    Spring Data Rest 可以返回 ALPS 或 JSON Schema,只需更改 Accept 标头:

    Accept: application/schema+json
    GET http://example.com/profile/foos
    

    所以,如果你有这样的实体:

    @Entity
    @AllArgsConstructor
    @NoArgsConstructor
    @Getter
    public class Foo {
        
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private Long id;
    
        private String owner;
    
        private String name;
    }
    

    你会得到这样的回应:

    {
      "title": "Foo",
      "properties": {
        "owner": {
          "title": "Owner",
          "readOnly": false,
          "type": "string"
        },
        "name": {
          "title": "Name",
          "readOnly": false,
          "type": "string"
        }
      },
      "definitions": {},
      "type": "object",
      "$schema": "http://json-schema.org/draft-04/schema#"
    }
    

    【讨论】:

      猜你喜欢
      • 2014-12-10
      • 1970-01-01
      • 1970-01-01
      • 2013-09-05
      • 1970-01-01
      • 2022-01-07
      • 2019-09-23
      • 2012-05-22
      • 1970-01-01
      相关资源
      最近更新 更多