apachecamel-Swagger-使用JPA实体作为rest类型
我有一个剩余的DSL:apachecamel-Swagger-使用JPA实体作为rest类型,jpa,apache-camel,swagger,swagger-ui,Jpa,Apache Camel,Swagger,Swagger Ui,我有一个剩余的DSL: // this api creates new user rest("/user") .post() .type(User.class).to("jpa://com.project.User") 这是我的实体: public class User{ @Id private String id; @ManyToOne @JoinColumn(name = "id_role") private Role role; }
// this api creates new user
rest("/user")
.post()
.type(User.class).to("jpa://com.project.User")
这是我的实体:
public class User{
@Id
private String id;
@ManyToOne
@JoinColumn(name = "id_role")
private Role role;
}
public class Role{
@Id
private String id;
@OneToMany(mappedBy="user")
private List<User> users;
}
非常复杂,尽管我只需要id
和id\u角色
参数来创建(发布)新用户。我希望身体的例子显示如下:
{
"id": "string",
"role": {
"id": "string",
"users": [
{
"id": "string",
"roles": [
{}
]
}
]
}
}
{
"id": "string",
"id_role": "string"
}
我意识到我的实体没有被正确地创建。这些是我学到的:
@实体
公共类用户{
@身份证
私有字符串id;
@许多酮
@JoinColumn(name=“id\u角色”)
私人角色;
}
@实体
公共阶级角色{
@身份证
私有字符串id;
@OneToMany(mappedBy=“user”,cascade=CascadeType.ALL)
私人名单用户;
}
@Entity
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "id")
public class User{
@Id
private String id;
@ManyToOne
@JoinColumn(name = "id_role")
private Role role;
}
@Entity
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "id")
public class Role{
@Id
private String id;
@OneToMany(mappedBy="user", cascade = CascadeType.ALL)
@JsonIgnore
// this attribute will not appear inside Role class
private List<User> users;
}
@实体
@JsonIdentityInfo(
生成器=ObjectedGenerators.PropertyGenerator.class,
property=“id”)
公共类用户{
@身份证
私有字符串id;
@许多酮
@JoinColumn(name=“id\u角色”)
私人角色;
}
@实体
@JsonIdentityInfo(
生成器=ObjectedGenerators.PropertyGenerator.class,
property=“id”)
公共阶级角色{
@身份证
私有字符串id;
@OneToMany(mappedBy=“user”,cascade=CascadeType.ALL)
@杰索尼奥雷
//此属性不会出现在角色类中
私人名单用户;
}
您可能需要向模型类添加招摇过市注释,因为它可能不理解JPA注释。
@Entity
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "id")
public class User{
@Id
private String id;
@ManyToOne
@JoinColumn(name = "id_role")
private Role role;
}
@Entity
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "id")
public class Role{
@Id
private String id;
@OneToMany(mappedBy="user", cascade = CascadeType.ALL)
@JsonIgnore
// this attribute will not appear inside Role class
private List<User> users;
}