項目中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的單元測試Junit
spring提供的單元測試是強大的,spring的單元測試很簡單,封裝的很好。我們要用spring的單元測試測試我們寫的add,delete等方法時候需要spring提供的一個額外包spring-mock.jar,我已經傳上來了。你只要熟悉單元測試,編寫一個測試案例,然后把繼承改為org.springframework.test.AbstractTransactionalDataSourceSpringContextTests就可以了,此時編譯器會提示你要實現
/**
* 必須實現的方法
*/
public String[] getConfigLocations(){
String[] config = new String[]{"applicationContext.xml","applicationContext-dao.xml","applicationContext-hibernate.xml","applicationContext-service.xml"};
return config;
}
看了大家應該明白,就是把你配置好的xml賦值給它,
然后大家就可以通過下面方法:
下面的applicationContext這個變量是你只要繼承了剛才那個抽象類就可以得到的一個恒量。
FriendService friendService = (FriendService)applicationContext.getBean("friendService");
得到你的實例來進行業務邏輯測試了,是不是很簡單,大家試試吧,它在此時完成以后會把數據庫回滾一次,不會影響你的數據庫記錄,非常好。
spring中提供 ContextLoaderListenter類,用來加載context的xml文件。
spring為struts提供ContextLoaderPlugIn類,此類也可以加載context的xml文件。
區別在于,兩種方式加載的WebApplicationContext,以不同的Key存放在ServletContext中。而如果你定義了HibernateFilter的話,spring會利用WebApplicationContextUtils來獲取WebApplicationContext,而此類并不識別ContextLoaderPlugIn類所加載的上下文,此時便會拋出異常: No WebApplicationContext found: no ContextLoaderListener registered?
利用ContextLoaderListenter來加載dao、service級別的context,而對于struts的action,用ContextLoaderPlugIn加載。
2005年漂泊的一年,先后求職于南京,上海和北京三地,因此慘遭京滬寧三地java高手蹂躪。
這些都是面試java架構師的比較變態的題目:
1。變態指數 4
int x=4;
System.out.println("value is " +((x>4)?99.9:9));
答案 9.0 問號表達式的后面兩個條件有要求,因為前面的是float,所以后面轉為float.
估計出題者才通過SCJP的考試。
2.變態指數 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.變態指數 6
String s=new String("abc");
創建了幾個String對象?
答案 2個
這樣的公司最好不要去
4.變態指數 7
const是不是java的關鍵字?
答案 const是java的關鍵字,但是java沒有實現它
一般人絕對用不到它
5.變態指數 8
,short s1 = 1; s1 = s1 + 1;有什么錯? short s1 = 1; s1 += 1;有什么錯?
答案 1錯2對,1因為向上轉型了,最后導致類型不匹配錯誤 ,
因為s1的+=是一個操作符,能夠自動轉型,
short s1 = 1;
s1 = s1+1;這句話在c++里面可以的
不知道出題人的意圖
6.變態指數 9
上海貝爾的面試題:你認為效率最高的方法,實現從1加到100.
答案 1-100的累加相當于加50次101,這樣循環次數從100次降為50次:
int sun = 0
for(int i = 1,j = 100 ; i <= 50 ; i++,j--){
sun = sun + i + j;
}
出題人腦子有問題,直接(1+100)*50不是最快...其實類似這樣的優化應該不是程序員考慮的范疇吧
7.變態指數 10
System.out.println(5.0942*1000);
System.out.println(5.0943*1000);
System.out.println(5.0944*1000);的結果
答案 :5094.2 5094.299999999999 5094.400000000001
原理和浮點數的計算機表示方式有關 ,你不用上機,就答對了,你最好去微軟,接替安德爾森.
posted on 2007-07-05 17:33
larryjava 閱讀(897)
評論(0) 編輯 收藏