[轉(zhuǎn)]項(xiàng)目中Struts/Spring/Hibernate的基本流程

          轉(zhuǎn)自:http://www.aygfsteel.com/larry/archive/2007/07/05/128419.html

          項(xiàng)目中
          Struts/Spring/Hibernate的基本流程

           

          Struts+Spring+Hibernate  develepment process:

          1.Write your business class : DTO,FormBean,Action,Service Interface,Service Implementation.

           2.Write JSP pages.
          3.struts-config.xml Configuration : FormBean,Action,Forward pages.
          4.applicationContext-service.xml Configuration: add your Service Interface and Service Implementation.
          5.Add your service factory Get method to ServiceFactory.java
          6.Build project and Generate the Description file(*.hbm.xml) of DTO.
          7.applicationContext.xml Configuration: add *.hbm.xml file to applicationContext for O/R mapping. 

          Spring+hibernate的單元測(cè)試Junit

           spring提供的單元測(cè)試是強(qiáng)大的,spring的單元測(cè)試很簡(jiǎn)單,封裝的很好。我們要用spring的單元測(cè)試測(cè)試我們寫的adddelete等方法時(shí)候需要spring提供的一個(gè)額外包spring-mock.jar,我已經(jīng)傳上來了。你只要熟悉單元測(cè)試,編寫一個(gè)測(cè)試案例,然后把繼承改為org.springframework.test.AbstractTransactionalDataSourceSpringContextTests就可以了,此時(shí)編譯器會(huì)提示你要實(shí)現(xiàn)
            /**
            *  必須實(shí)現(xiàn)的方法
            */
            public  String[]  getConfigLocations(){
            String[]  config  =  new  String[]{"applicationContext.xml","applicationContext-dao.xml","applicationContext-hibernate.xml","applicationContext-service.xml"};
            return  config;
            }
            看了大家應(yīng)該明白,就是把你配置好的xml賦值給它,
            然后大家就可以通過下面方法:
            下面的applicationContext這個(gè)變量是你只要繼承了剛才那個(gè)抽象類就可以得到的一個(gè)恒量。
            FriendService  friendService  =  (FriendService)applicationContext.getBean("friendService");
            得到你的實(shí)例來進(jìn)行業(yè)務(wù)邏輯測(cè)試了,是不是很簡(jiǎn)單,大家試試吧,它在此時(shí)完成以后會(huì)把數(shù)據(jù)庫(kù)回滾一次,不會(huì)影響你的數(shù)據(jù)庫(kù)記錄,非常好。

           

          spring中提供 ContextLoaderListenter類,用來加載contextxml文件。

          springstruts提供ContextLoaderPlugIn類,此類也可以加載contextxml文件。

          區(qū)別在于,兩種方式加載的WebApplicationContext,以不同的Key存放在ServletContext中。而如果你定義了HibernateFilter的話,spring會(huì)利用WebApplicationContextUtils來獲取WebApplicationContext而此類并不識(shí)別ContextLoaderPlugIn類所加載的上下文,此時(shí)便會(huì)拋出異常: No WebApplicationContext found: no ContextLoaderListener registered?

          利用ContextLoaderListenter來加載daoservice級(jí)別的context,而對(duì)于strutsaction,用ContextLoaderPlugIn加載。

          2005年漂泊的一年,先后求職于南京,上海和北京三地,因此慘遭京滬寧三地java高手蹂躪。
          這些都是面試java架構(gòu)師的比較變態(tài)的題目:
          1
          。變態(tài)指數(shù) 4
          int x=4;
          System.out.println("value is " +((x>4)?99.9:9));
          答案 9.0 問號(hào)表達(dá)式的后面兩個(gè)條件有要求,因?yàn)榍懊娴氖?span>float,
          所以后面轉(zhuǎn)為float.
          估計(jì)出題者才通過SCJP的考試。
          2.
          變態(tài)指數(shù) 5
          public class Test {

          public static void main(String[] args) {
          int x = 4;
          java.util.Date date = (x > 4) ? new A() : new B();
          }
          }

          class A extends java.util.Date {}
          class B extends java.util.Date {}
          答案 jdk1.4編譯不通過,1.5可以
          不知道出題人的意圖
          3.
          變態(tài)指數(shù) 6
          String s=new String("abc");
          創(chuàng)建了幾個(gè)String對(duì)象?
          答案 2個(gè)
          這樣的公司最好不要去

          4.變態(tài)指數(shù) 7
          const
          是不是java的關(guān)鍵字?
          答案 constjava的關(guān)鍵字,但是java沒有實(shí)現(xiàn)它
          一般人絕對(duì)用不到它

          5.
          變態(tài)指數(shù) 8
          short s1 = 1; s1 = s1 + 1;有什么錯(cuò)? short s1 = 1; s1 += 1;有什么錯(cuò)?
          答案 1錯(cuò)2對(duì),1因?yàn)橄蛏限D(zhuǎn)型了,最后導(dǎo)致類型不匹配錯(cuò)誤 ,
          因?yàn)?span>s1
          +=是一個(gè)操作符,能夠自動(dòng)轉(zhuǎn)型,
          short s1 = 1;
          s1 = s1+1;
          這句話在c++里面可以的
          不知道出題人的意圖
          6.
          變態(tài)指數(shù) 9
          上海貝爾的面試題:你認(rèn)為效率最高的方法,實(shí)現(xiàn)從1加到100.
          答案 1-100的累加相當(dāng)于加50101,這樣循環(huán)次數(shù)從100次降為50次:
          int sun = 0
          for(int i = 1,j = 100 ; i <= 50 ; i++,j--){
              sun = sun + i + j;

          出題人腦子有問題,直接(1+100)*50不是最快...其實(shí)類似這樣的優(yōu)化應(yīng)該不是程序員考慮的范疇吧
          7.
          變態(tài)指數(shù) 10
           System.out.println(5.0942*1000);
               System.out.println(5.0943*1000);
            System.out.println(5.0944*1000);
          的結(jié)果
          答案 :5094.2 5094.299999999999 5094.400000000001
          原理和浮點(diǎn)數(shù)的計(jì)算機(jī)表示方式有關(guān) ,你不用上機(jī),就答對(duì)了,你最好去微軟,接替安德爾森.

          posted on 2007-08-30 23:10 hijackwust 閱讀(438) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          <2007年8月>
          2930311234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(6)

          隨筆檔案(57)

          友情鏈接

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 扬州市| 夏津县| 崇仁县| 西青区| 克山县| 黔西县| 舞阳县| 图片| 繁昌县| 临漳县| 克山县| 莆田市| 梅州市| 栾城县| 论坛| 安图县| 满城县| 饶河县| 绥中县| 讷河市| 津南区| 临桂县| 石台县| 松溪县| 屯留县| 中方县| 余姚市| 高雄县| 栖霞市| 扎囊县| 江西省| 会理县| 浠水县| 辽中县| 四川省| 拉萨市| 皮山县| 大洼县| 大连市| 舒城县| 鹤壁市|