【发布时间】:2021-10-21 15:12:56
【问题描述】:
我了解到在每个端点上编写 @Consumes 和 @Produces 注释是很好的编程。但是,如果我在端点声明类型,我还需要注解吗?
什么是好的编程?
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces("application/pdf") // Content type declared in annotation
@Path(GET_BILL_FOR_SYSTEM)
public Response getBillForTheSystem(@QueryParam(value = "year") Long year) {
return Response.ok( billSheetService.getBillForTheSystem(year) )
.type( "application/pdf" ) // Content type declared in response builder
.header( "Content-Disposition", "attachment; filename=\"BillForTheSystem.pdf\"" )
.build();
}
【问题讨论】: