??? 很長(zhǎng)時(shí)間沒(méi)有寫B(tài)LOG了,先啰嗦幾句。
??? 我已經(jīng)從一家不知名的小公司又一次回到了大公司里了,這是我7年工作來(lái)又一次回歸大公司。當(dāng)然了小公司有小公司的心胸狹窄和陰險(xiǎn),大公司有嚴(yán)格的管理制度和進(jìn)升方式,這都不能夠相提并論。所以建議有能力的朋友在大公司里做事,能夠讓自己用正確的方式做正確的事。
?-----------------------天行鍵,君子以自強(qiáng)不息!
??? 話入正題。
??? 在大家的編碼過(guò)程當(dāng)中,有沒(méi)有遇到過(guò)這么一種情況,很多零亂的狀態(tài)、分類和其它常用選項(xiàng)常常是定義死了。但是沒(méi)有一個(gè)完整的東東來(lái)約束他,在每個(gè)模塊當(dāng)中使用相關(guān)的信息時(shí),往往重新COPY一次,或者COPY過(guò)來(lái)修改一次。如果多人協(xié)作的話,務(wù)必會(huì)讓代碼變的零亂、不好管理等。
??? 本次主要是把一些靜態(tài)的分類、狀態(tài)或者其它常用選項(xiàng)使用二維數(shù)組管理起來(lái)。如果你是一個(gè)使用JSTL或者STRUTS做前臺(tái)表現(xiàn)的話,你就更應(yīng)該好好關(guān)注了。
??? 以下以一個(gè)審核的狀態(tài)做示例,使用代碼實(shí)現(xiàn)(光說(shuō)不練是假功夫).
創(chuàng)建Config.java
package?com.antbee;
import?java.util.ArrayList;
import?java.util.List;
/**
?*?<p>
?*?</p>
?*?
?*?<p>
?*?Copyright:?版權(quán)所有?(c)?2002?-?2006
?*?</p>
?*?<p>
?*?Company:?Antbee
?*?</p>
?*?
?*?@author?@家軍
?*?@version?1.0
?*/
public?class?Config?{
????/**
?????*?客戶狀態(tài)
?????*/
????Object?vec[][]?=?{?{?new?Integer(1),?new?String("申請(qǐng)"),new?String("apply")},
????????????{?new?Integer(2),?new?String("待審核"),new?String("auditing")?},
????????????{?new?Integer(3),?new?String("簽約"),new?String("sign?up")?},
????????????{?new?Integer(4),?new?String("續(xù)簽中"),new?String("nominator")?},
????????????{?new?Integer(5),?new?String("過(guò)期"),new?String("overdue")?}?};
????public?List?Stutas?=?GetConfigEntity(vec);????
????public?List?GetConfigEntity(Object?allconfig[][])?{
????????List?ConfigList?=?new?ArrayList();
??? ??? ConfigEntity first = new ConfigEntity();
??? ??? first.setTypeSeri(Integer.valueOf("0"));
??? ??? first.setTypeCnName("請(qǐng)選擇");
??? ??? first.setTypeEnName("Pls Select");
??? ??? ConfigList.add(first);
????????for(int?i=0;i<allconfig.length;i++){
????????????ConfigEntity?configEntity?=?new?ConfigEntity();????????????
????????????configEntity.setTypeSeri(Integer.valueOf(allconfig[i][0].toString()));
????????????configEntity.setTypeCnName(allconfig[i][1].toString());
????????????configEntity.setTypeEnName(allconfig[i][2].toString());
????????????ConfigList.add(configEntity);
????????}
????????return?ConfigList;
????}
}
對(duì)應(yīng)的PO實(shí)體類ConfigEntity.java(如果有數(shù)據(jù)庫(kù)的話,你就可以直接從數(shù)據(jù)庫(kù)當(dāng)中取)
package?com.antbee;
import?java.io.Serializable;
public?class?ConfigEntity?implements?Serializable?{
???????/**?The?cached?hash?code?value?for?this?instance.??Settting?to?0?triggers?re-calculation.?*/
????private?int?hashValue?=?0;
????/**?The?composite?primary?key?value.?*/
????private?java.lang.Integer?typeSeri;
????/**?The?value?of?the?simple?typeName?property.?*/
????private?java.lang.String?typeCnName;
????
????/**?The?value?of?the?simple?typeName?property.?*/
????private?java.lang.String?typeEnName;
????/**
?????*?Simple?constructor?of?AbstractDicType?instances.
?????*/
????public?ConfigEntity()
????{
????}
????/**
?????*?Constructor?of?AbstractDicType?instances?given?a?simple?primary?key.
?????*?@param?typeSeri
?????*/
????public?ConfigEntity(java.lang.Integer?typeSeri)
????{
????????this.setTypeSeri(typeSeri);
????}
????/**
?????*?Return?the?simple?primary?key?value?that?identifies?this?object.
?????*?@return?java.lang.Integer
?????*/
????public?java.lang.Integer?getTypeSeri()
????{
????????return?typeSeri;
????}
????/**
?????*?Set?the?simple?primary?key?value?that?identifies?this?object.
?????*?@param?typeSeri
?????*/
????public?void?setTypeSeri(java.lang.Integer?typeSeri)
????{
????????this.hashValue?=?0;
????????this.typeSeri?=?typeSeri;
????}
????/**
?????*?Return?the?value?of?the?TYPE_NAME?column.
?????*?@return?java.lang.String
?????*/
????public?java.lang.String?getTypeCnName()
????{
????????return?this.typeCnName;
????}
????/**
?????*?Set?the?value?of?the?TYPE_NAME?column.
?????*?@param?typeName
?????*/
????public?void?setTypeCnName(java.lang.String?typeCnName)
????{
????????this.typeCnName?=?typeCnName;
????}???
????/**
?????*?Return?the?value?of?the?TYPE_NAME?column.
?????*?@return?java.lang.String
?????*/
????public?java.lang.String?getTypeEnName()
????{
????????return?this.typeEnName;
????}
????/**
?????*?Set?the?value?of?the?TYPE_NAME?column.
?????*?@param?typeName
?????*/
????public?void?setTypeEnName(java.lang.String?typeEnName)
????{
????????this.typeEnName?=?typeEnName;
????}?
????
????/**
?????*?Implementation?of?the?equals?comparison?on?the?basis?of?equality?of?the?primary?key?values.
?????*?@param?rhs
?????*?@return?boolean
?????*/
????public?boolean?equals(Object?rhs)
????{
????????if?(rhs?==?null)
????????????return?false;
????????if?(!?(rhs?instanceof?ConfigEntity))
????????????return?false;
????????ConfigEntity?that?=?(ConfigEntity)?rhs;
????????if?(this.getTypeSeri()?==?null?||?that.getTypeSeri()?==?null)
????????????return?false;
????????return?(this.getTypeSeri().equals(that.getTypeSeri()));
????}
????/**
?????*?Implementation?of?the?hashCode?method?conforming?to?the?Bloch?pattern?with
?????*?the?exception?of?array?properties?(these?are?very?unlikely?primary?key?types).
?????*?@return?int
?????*/
????public?int?hashCode()
????{
????????if?(this.hashValue?==?0)
????????{
????????????int?result?=?17;
????????????int?typeSeriValue?=?this.getTypeSeri()?==?null???0?:?this.getTypeSeri().hashCode();
????????????result?=?result?*?37?+?typeSeriValue;
????????????this.hashValue?=?result;
????????}
????????return?this.hashValue;
????}
}
具體使用方法
/*Antbee?@家軍
*/
Config?n?=?new?Config();
List?View_Stutas?=?n.Stutas;????????request.setAttribute("View_Stutas",?View_Stutas);
頁(yè)面當(dāng)中示例:
<c:forEach?items="${View_Stutas}"?var="View_Stutas">
??????????????<option?value="<c:out?value="${View_Stutas.typeSeri?}"?/>"><c:out?value="${View_Stutas.typeEnName}"/></option>
???????????</c:forEach>
可以看出,在實(shí)體類里一共有三個(gè)方法,其它有兩個(gè)名字, 一個(gè)是中文名字,一個(gè)是英文名字,你可以在頁(yè)面當(dāng)中截取本地語(yǔ)言并顯示其中一個(gè)語(yǔ)言就行。