java - 为 springboot 微服务创建 pojo
问题描述
我想在 Spring Boot 中开发一个微服务应用程序。我创建了 2 个服务,称为用户服务和配方服务。
我的问题是一个用户可以有多个食谱,但我无法确定食谱字段的类型。我不能使用private List<Recipe> recipes
,因为我希望每个微服务都应该是独立的。你有什么主意吗?
如果我这样确定private List<Long> recipes
如何向邮递员发送请求?
{
"id": 102,
"userName": "figen",
"email": 3,
"recipes":5,6,7 // line 5
}
由于第 5 行,此请求不起作用
import org.springframework.data.mongodb.core.mapping.Document;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
//@Entity
@Document(collection = "User")
public class User {
@Id
private String id;
private String userName;
private Long email;
private List<Long> recipes; // I cannot determine this type(one-to-many relationship)
public User(){
}
public User(String id, String userName, Long email,List<Long> recipes) {
this.id = id;
this.userName = userName;
this.email = email;
this.notes = recipes;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Long getEmail() {
return email;
}
public void setEmail(Long email) {
this.email = email;
}
public List<Long> getRecipes() {
return recipes;
}
public void setRecipes(List<Long> recipes) {
this.notes = recipes;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", userName='" + userName + '\'' +
", email='" + email + '\'' +
", recipes=" + recipes+
'}';
}
}
解决方案
在食谱中添加 [] 后它将起作用。
{
"id": 102,
"userName": "figen",
"email": 3,
"recipes":[5,6,7]
}
推荐阅读
- php - laravel 生成正则表达式来验证输入
- azure - 是否有验证导出的 Azure ARM 模板的好方法?
- apache-camel - cvc-complex-type.3.2.2:属性“exceptionType”不允许出现在元素“throwException”中
- c# - 区分根 CA 和中间 CA 证书
- python - 'NoneType' 对象没有属性 'name' - 当模型之间建立通信时。Flask
- elasticsearch - NLog Elasticsearch 集成 @timestamp 在 ES 中工作错误(提前 2 小时)
- android - 避免布局元素太大时将第二个元素移出布局
- vb.net - 如何删除按钮的焦点矩形?
- java - 从数据库中删除一行有什么问题?
- html - 输入控制文本根据屏幕大小调整大小