例如,我希望在我的Spring启动应用程序中获得这样的JSON:
def main():
n_samples = 256
n_features = 16
n_labels = 1
x = np.random.rand(n_samples, n_features).astype(np.float32)
y = np.random.rand(n_samples, n_labels).astype(np.float32)
feature_column = tf.contrib.layers.real_valued_column(
column_name='features', dimension=n_features)
# Use the `tf.estimator.DNNRegressor` constructor instead of
# `tf.contrib.learn.DNNRegressor`.
estimator = tf.estimator.DNNRegressor(
[10], [feature_column], optimizer=tf.train.AdamOptimizer())
# Replace `estimator.fit()` with `estimator.train()`.
estimator.train(input_fn=lambda: input_function(
x, y, batch_size=128, shuffle=True, n_epochs=32))
# Replace `estimator.predict_scores()` with `estimator.predict()`.
pred = estimator.predict(input_fn=lambda: input_function(
x, y, batch_size=16, shuffle=False, n_epochs=1))
print("len(pred) = {} (should be {})".format(len(list(pred)), n_samples))
我有@Entity注释类:
{
"firstName": "John",
"lastName": "Doe",
"phoneNumbers": [
"453 123-1234",
"753 123-4567"
]
}
然后,如果我向端点发送请求,我会得到这样的回复:
@Entity
public class MyEntity {
String firstName;
String lastNAme;
String phoneNumbers;
//constructors, getters and setters...
}
其中phoneNumbers只是一个字符串,但不是数组。 我尝试了设计phoneNumbers字段的不同变体,作为数组或集合,并使用注释,例如@ElementCollection,但只有异常或错误消息在请求后返回。 如何解决这个问题?
答案 0 :(得分:3)
您需要一个电话号码列表
public class MyEntity {
private String firstName;
private String lastNAme;
private List<String> phoneNumbers;
答案 1 :(得分:1)
作为一个好的数据库设计
这些关系实体应具有类似下面的列
ParentEntity
entity_id first_name last_name
PhoneNumber
child_id entity_id phone_number
在模型类中使用这些映射配置
@Entity
public class ParentEntity {
@Id
private long entityId;
private String firstName;
private String lastName;
@OneToMany(mappedBy="parentEntity")
private Set<PhoneNumber> phoneNumbers;
}
@Entity
public class PhoneNumber {
@Id
private long childId;
@ManyToOne
@JoinColumn(name = "entityId")
private ParentEntity parentEntity
private int phoneNumber;
}