我了解到在每個端點上撰寫@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();
}
uj5u.com熱心網友回復:
你是對的。兩次宣告回應內容型別的值沒有任何功能上的原因。事實上,這種重復往往是不受歡迎的。
但是,如果您擁有檢查代碼以生成檔案的工具,則它可能能夠讀取注釋,但無法讀取代碼本身回傳的型別。所以在那種情況下,我寧愿只留下注釋。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/335680.html
