我正在使用springboot 1.5.4,springfox-swagger2-2.7.0来开发springboot应用程序,并使用swagger for rest api文档。 Swagger文档和rest api响应都显示了相关对象的所有属性,我也不想显示这些字段。
我的实体类:
@Entity
public class Account {
@Id
@GeneratedValue
private Long accountId;
private String accountUid;
private String accountName;
private String contactPerson;
private String emailId;
@ManyToOne
@JoinColumn(name = "account_type_id")
private AccountType accountType;
// ...setter and getters
}
@Entity
public class AccountType {
@Id
@GeneratedValue
private Long accountTypeId;
private String typeName;
private String description;
private int status;
// setter and getters
}
swagger documentaion中的模型类是:
{
"accountId": 0,
"accountName": "string",
"accountUid":"string",
"accountType": {
"accountTypeId": 0,
"description": "string",
"status": 0,
"typeName": "string"
},
"contactPerson": "string",
"emailId": "string"
}
获取帐户的回复是:
{
"accountId": 1,
"accountName": "xxxxx",
"contactPerson": "xxxx",
"emailId": "test.abc@abc.com",
"accountType": {
"accountTypeId": 1,
"typeName": "xxxxx",
"description": "xxxxx",
"status": 1
}
}
但是在回复和招摇中,我也不想显示帐户类型的所有属性,除了id。 我想要的输出是
{
"accountId": 1,
"accountName": "xxxxx",
"contactPerson": "xxxx",
"emailId": "test.abc@abc.com",
"accountType": {
"accountTypeId": 1
}
}
我无法找到问题是swagger还是spring数据JPA。