如何将 @RequestParam 与嵌套对象一起使用
我需要将来自 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论