Spring專案開發筆記系列(五)

2021-06-15 21:24:30 字數 1541 閱讀 2299

spring專案開發筆記系列(五)

---hibernate持久化類的annotation方式配置

spring的這個專案中主要用的配置檔案就前面這麼幾個web.xml,spring-config.xml和struts-config.xml,其它的配置檔案比如log4j.properties,validation.xml就不發了,都是以前的配置方式。現在還有乙個就是hibernate3.2的持久化類的annotation配置方式,如下:

1,所有持久化類的基類:

2,持久化類user:

@entity

@table(name="sys_user")

public class user extends hibernateobject

public void setpassword(string password)

@column(name="***",length=5)

public string get***()

public void set***(string ***)

@column(name="age")@range(min=0,max=120)

public int getage()

public void setage(int age)

@column(name="mobile",length=20)

public string getmobile()

public void setmobile(string mobile)

@column(name="address")

public string getaddress()

public void setaddress(string address)

@column(name="email",length=100)@email

public string getemail()

public void setemail(string email)

}這樣配置後,我們無需在生成user.hbm.xml檔案了,另外的sql檔案也無需再生成了,當我們執行這個持久化類的時候,成序會自動建立乙個名字叫「sys_user」的table在我們制定的資料庫中~

好了,經過這幾步的配置,主要的配置檔案和只要技術也就用到了,剩下的就是寫dao,action子類的了,我就不再往上貼了~~

這樣的配置個人感覺他的好處就在於

1,配置檔案少,減少了hibernate配置檔案和對映檔案

2,hibernate,spring,struts各部分界線比較清晰,便於維護

3,儘量減少了額外操作,如無需再去生成hibernate對映檔案(.hbm.xml)等

以上程式在windowsxp,jdk1.5.0_11,tomcat5.0/6.0,windowsxp,所需lib檔案和整體框架在spring專案開發筆記系列(一)中已經列出(補充乙個lib:commons-collections-3.2.jar),

在spring專案開發筆記系列(六)中我會把最新的專案結構重新列出來!

寫的難免有不當的地方,請發現的朋友及時指出~~^_^

專案開發筆記

專案中可以考慮整合的 網路請求類 universal image loader 快取及方便的網路讀取類庫,若上述volley庫沒用到且只需方便的類庫可以選擇這個 sharesdk 整合了主流各大社交平台的分享及其第三方平台的登入,也支援自定義ui 資料解析類 gson fastjson 若互動資料以...

Spring開發筆記 Spring 集合注入詳解

csdn2 csdn3 csdn4 listlist gs.getlists for string str list 注入set集合的方法 1 在要注入的類中定義要注入的集合 比如 sets 並生成其getter和setter方法 2 修改配置檔案,增加屬性 set csdn1 set csdn2 ...

0065 專案開發筆記

ogre中遇到的注意事項 1 material檔案中的名字不能是中文!2 ogre執行路徑不能是中文名字!3 material檔案中如果設定環境光 ambient 和 diffuse 會影響材質貼圖的顯示,一般設定成lighting off 4 ofusion外掛程式,支援3dsmax 7,8,9 ...