Liferay 常用基礎類 —— com.liferay.util.ParamUtil

位置:com.liferay.util.ParamUtil

作用:
從request 裏獲取指定屬性的值。

傳入參數: 有兩類方法
  • 無默認值 —— get[DateType]( ServletRequest req, String param ) 其中紅色[DateType] 表示所預知返回屬性值的類型。比如當所獲取屬性爲時間(Date)類型時可調用getDate(ServletRequest req, String param, DateFormat df),其中Param 爲字符串型的屬性名。該方法獲得的即爲ServletRequest 類的實例req 中,名爲param 的屬性的時間值,並以 df 的形式表示。
  • 有默認值 :有默認值時可有兩種方法調用。
    •  get[DateType]( ServletRequest req, String param, [DateType] defaultValue ):  其中紅色[DateType] 表示所預知返回屬性值的類型。比如當所獲取屬性爲時間(Date)類型時可調用getDate(ServletRequest req, String param, DateFormat df, Date defaultValue),其中Param 爲字符串型的屬性名。該方法獲得的即爲ServletRequest 類的實例req 中,名爲param 的屬性的時間值,並以 df 的形式表示。若未能從req 中獲取到值,則返回默認值defaultValue。
    • get(ServletRequest req, String param, [DateType] defaultValue): 其中紅色[DateType] 表示所預知返回屬性值的類型。比如當所獲取屬性爲時間(Date)類型時可調用get (ServletRequest req, String param, DateFormat df, Date defaultValue),其中Param 爲字符串型的屬性名。該方法獲得的即爲ServletRequest 類的實例req 中,名爲param 的屬性的時間值,並以 df 的形式表示。若未能從req 中獲取到值,則返回默認值defaultValue。
注意:Date 類型值獲取時引入了DateFormat 對象對Date 的表現形式進行約束。其它基礎類的值獲取時則沒有此項參數,刻按照以上方法進行調用。
發佈了24 篇原創文章 · 獲贊 1 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章