如何将 @RequestParam 与嵌套对象一起使用

发布于 2025-01-13 00:03:07 字数 1653 浏览 0 评论 0原文

我需要将来自 JSON 的二维数组转换为字符串。我只需要操纵这个值。

有一个 JSON 示例:

https://en.wikipedia.org/wiki/GeoJSON

@RequestMapping 是操作来自 REST 的值的方法。但我不知道如何对嵌套对象执行此操作。

    @ResponseBody
    public GeoJson saveData(@RequestParam {What i need}...) throws IOException{
        return geoJSONRepository.save(geoJson);
    }

GeoJson 类:

@Entity
public class GeoJson {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    private String type;
    @OneToMany(cascade = CascadeType.ALL)
    @ToString.Exclude
    private List<Feature> features = new ArrayList<Feature>();
    public GeoJson() {
    }
}

要素类:

@Entity
public class Feature {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long fId;
    private String type;
    @OneToOne(cascade = CascadeType.ALL)
    private Properties properties;
    @OneToOne(cascade = CascadeType.ALL)
    private Geometry geometry;
}

属性类:

@Entity
public class Properties {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "pId", nullable = false)
    private Long pId;
    @Column(name = "property_type")
    private String type;
}

几何类:

@Entity
public class Geometry {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "gId", nullable = false)
    private Long gId;
    private String type;
    private String coordinates; //2-d coordinates value

}

I need to convert 2-D array comes from JSON to a string. I just need to manipulate that value.

There is an example of the JSON:

https://en.wikipedia.org/wiki/GeoJSON

@RequestMapping is the way to manipulate value that comes from REST. But i dont know how to do it for nested object.

    @ResponseBody
    public GeoJson saveData(@RequestParam {What i need}...) throws IOException{
        return geoJSONRepository.save(geoJson);
    }

GeoJson class:

@Entity
public class GeoJson {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    private String type;
    @OneToMany(cascade = CascadeType.ALL)
    @ToString.Exclude
    private List<Feature> features = new ArrayList<Feature>();
    public GeoJson() {
    }
}

Feature class:

@Entity
public class Feature {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long fId;
    private String type;
    @OneToOne(cascade = CascadeType.ALL)
    private Properties properties;
    @OneToOne(cascade = CascadeType.ALL)
    private Geometry geometry;
}

Properties class:

@Entity
public class Properties {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "pId", nullable = false)
    private Long pId;
    @Column(name = "property_type")
    private String type;
}

Geometry class:

@Entity
public class Geometry {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "gId", nullable = false)
    private Long gId;
    private String type;
    private String coordinates; //2-d coordinates value

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文