请问一下如何改变Swagger的参数输入。很难说明白,进来看下图片

yang147896523 2018-11-16 10:11:19
最近学Restful 的技术,搭了一个 JPA+hibernate+jboss+swagger,然后这个是我的customer的实体类

@Entity
@NamedQueries({
@NamedQuery(name = Customer.FIND_ALL, query = "SELECT c FROM Customer c ORDER BY c.lastName ASC, c.firstName ASC"),
@NamedQuery(name = Customer.FIND_BY_EMAIL, query = "SELECT c FROM Customer c WHERE c.email = :email")
})
@XmlRootElement
@Table(name = "customer", uniqueConstraints = @UniqueConstraint(columnNames = "email"))
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,property = "id")
public class Customer implements Serializable {


private static final long serialVersionUID = 1L;

public static final String FIND_ALL = "Customer.findAll";
public static final String FIND_BY_EMAIL = "Customer.findByEmail";

@Id
@GeneratedValue(strategy = GenerationType.TABLE)
@ApiModelProperty(hidden = true)
private Long id;

@OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<Booking> booking = new HashSet<Booking>();

set....get...


这个是Booking的实体类。 customer和booking一对多的关联,并且设置了customer_id在booking表是外键,关联customer的id

@Entity
@NamedQuery(name = Booking.FIND_ALL, query = "SELECT c FROM Booking c ORDER BY c.id ASC")
@XmlRootElement
@Table(name = "booking")
public class Booking implements Serializable {


private static final long serialVersionUID = 1L;

public static final String FIND_ALL = "Booking.findAll";

@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private Long id;

@NotNull
@ManyToOne
@JoinColumn(name = "customer_id")
@ApiModelProperty(readOnly = true)
private Customer customer;

set....get....


这个是Restful的POST接口代码,我是以Booking作为参数进行输入参数

@SuppressWarnings("unused")
@POST
@ApiOperation(value = "Add a new Booking to the database")
public Response createBooking(
@ApiParam(value = "JSON representation of Booking object to be added to the database", required = true)
Booking booking) {
.....
}


按照以上的代码,在Swagger上显示的是


可以看到,当我要求输入的参数是Booking类型的时候,Swagger显示需要输入Booking里的Customer类型的所有值,因为我只需要customer的id就可以了,所以如何不改变Booking参数的输入,而且还能将这个Customer输入的值改成只需要输入customer的id就可以,而且这个customer_id 是 在booking与customer进行关联的列名。
如下图显示的结果。是不是有什么其他注释可以做到这个效果?

...全文
321 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Insist_on_progress 2018-12-07
  • 打赏
  • 举报
回复
@PostMapping("save")
@ApiOperation("发布内容")
@CrossOrigin
public JSONResponse save(Content content) {
int save = service.save(content);
if (save > 0) {
return ResultUtil.success("发布成功");
}
return ResultUtil.success("发布失败");
}

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧