1.ç®è¿°ä¸ä¸Javaä¸çweb容å¨ï¼ä¸¾å 个ä¾åä¹è¡
2.java webå¼å ä¼çè¿
ç®è¿°ä¸ä¸Javaä¸çweb容å¨ï¼ä¸¾å 个ä¾åä¹è¡
ç®åå¸åºä¸å¸¸ç¨çå¼æºJava Web容å¨æTomcatãResinåJettyãå ¶ä¸Resinä»V3.0åéè¦è´ä¹°æè½ç¨äºåä¸ç®çï¼èå ¶ä»ä¸¤ç§åæ¯çº¯å¼æºçãå¯ä»¥åå«ä»ä»ä»¬çç½ç«ä¸ä¸è½½ææ°çäºè¿å¶å åæºä»£ç ã
ä½ä¸ºWeb容å¨ï¼éè¦æ¿åè¾é«ç访é®éï¼è½å¤åæ¶ååºä¸åç¨æ·ç请æ±ï¼è½å¤å¨æ¶å£ç¯å¢ä¸ä¿æè¾é«ç稳å®æ§åå¥å£®æ§ãå¨HTTPæå¡å¨é¢åï¼Apache HTTPDçæçæ¯æé«çï¼ä¹æ¯æ为稳å®çï¼ä½å®åªè½å¤çéæ页é¢ç请æ±ï¼å¦æéè¦æ¯æå¨æ页é¢è¯·æ±ï¼åå¿ é¡»å®è£ ç¸åºçæ件ï¼æ¯å¦mod_perlå¯ä»¥å¤çPerlèæ¬ï¼mod_pythonå¯ä»¥å¤çPythonèæ¬ã
ä¸é¢ä»ç»çä¸ä¸Web容å¨ï¼é½æ¯ä½¿ç¨Javaç¼åçHTTPæå¡å¨ï¼å½ç¶ä»ä»¬é½å¯ä»¥åµå°Apacheä¸ä½¿ç¨ï¼ä¹å¯ä»¥ç¬ç«ä½¿ç¨ãåæå®ä»¬å¤ç客æ·è¯·æ±çæ¹æ³æå©äºäºè§£Javaå¤çº¿ç¨å线ç¨æ± çå®ç°æ¹æ³ï¼ä¸ºè®¾è®¡å¼ºå¤§çå¤çº¿ç¨æå¡å¨æ好åºç¡ã
Tomcatæ¯ä½¿ç¨æ广çJava Web容å¨ï¼åè½å¼ºå¤§ï¼å¯æ©å±æ§å¼ºãææ°çæ¬çTomcatï¼5.5.ï¼ä¸ºäºæé«ååºé度åæçï¼ä½¿ç¨äºApache Portable Runtimeï¼APRï¼ä½ä¸ºæåºå±ï¼ä½¿ç¨äºAPRä¸å å«Socketãç¼å²æ± çå¤ç§ææ¯ï¼æ§è½ä¹æé«äºãAPRä¹æ¯Apache HTTPDçæåºå±ãå¯æ³èç¥ï¼åå±äºASFï¼Apache Software Foundationï¼ä¸çæåï¼äºè¡¥äºç¨çæ åµè¿æ¯å¾å¤çï¼è½ç¶ä½¿ç¨äºä¸åçå¼åè¯è¨ã
Tomcat ç线ç¨æ± ä½äºtomcat-util.jaræ件ä¸ï¼å å«äºä¸¤ç§çº¿ç¨æ± æ¹æ¡ãæ¹æ¡ä¸ï¼ä½¿ç¨APRçPoolææ¯ï¼ä½¿ç¨äºJNIï¼æ¹æ¡äºï¼ä½¿ç¨Javaå®ç°çThreadPoolãè¿éä»ç»çæ¯ç¬¬äºç§ãå¦ææ³äºè§£APRçPoolææ¯ï¼å¯ä»¥æ¥çAPRçæºä»£ç ã
ThreadPoolé»è®¤å建äº5个线ç¨ï¼ä¿åå¨ä¸ä¸ªç»´ç线ç¨æ°ç»ä¸ï¼å建æ¶å°±å¯å¨äºè¿äºçº¿ç¨ï¼å½ç¶å¨æ²¡æ请æ±æ¶ï¼å®ä»¬é½å¤çâçå¾ âç¶æï¼å ¶å®å°±æ¯ä¸ä¸ªwhile循ç¯ï¼ä¸åççå¾ notifyï¼ãå¦ææ请æ±æ¶ï¼ç©ºé²çº¿ç¨ä¼è¢«å¤éæ§è¡ç¨æ·ç请æ±ã
å ·ä½ç请æ±è¿ç¨æ¯ï¼ æå¡å¯å¨æ¶ï¼å建ä¸ä¸ªä¸ç»´çº¿ç¨æ°ç»ï¼maxThreadï¼ä¸ªï¼ï¼å¹¶å建空é²çº¿ç¨(minSpareThreadsï¼5个)éæ¶çå¾ ç¨æ·è¯·æ±ã å½æç¨æ·è¯·æ±æ¶ï¼è°ç¨ threadpool.runIt(ThreadPoolRunnable)æ¹æ³ï¼å°ä¸ä¸ªéè¦æ§è¡çå®ä¾ä¼ ç»ThreadPoolä¸ãå ¶ä¸ç¨æ·éè¦æ§è¡çå®ä¾å¿ é¡»å®ç°ThreadPoolRunnableæ¥å£ã ThreadPoolé¦å æ¥æ¾ç©ºé²ç线ç¨ï¼å¦ææåç¨å®è¿è¡è¦æ§è¡ThreadPoolRunnableï¼å¦æ没æ空é²çº¿ç¨å¹¶ä¸æ²¡æè¶ è¿maxThreadsï¼å°±ä¸æ¬¡æ§å建minSpareThreads个空é²çº¿ç¨ï¼å¦æå·²ç»è¶ è¿äºmaxThreadsäºï¼å°±çå¾ ç©ºé²çº¿ç¨äºãæ»ä¹ï¼è¦æ¾å°ç©ºé²ç线ç¨ï¼ä»¥ä¾¿ç¨å®æ§è¡å®ä¾ãæ¾å°åï¼å°è¯¥çº¿ç¨ä»çº¿ç¨æ°ç»ä¸ç§»èµ°ã æ¥çå¤éå·²ç»æ¾å°ç空é²çº¿ç¨ï¼ç¨å®è¿è¡æ§è¡å®ä¾ï¼ThreadPoolRunnableï¼ã è¿è¡å®ThreadPoolRunnableåï¼å°±å°è¯¥çº¿ç¨éæ°æ¾å°çº¿ç¨æ°ç»ä¸ï¼ä½ä¸ºç©ºé²çº¿ç¨ä¾åç»ä½¿ç¨ã
ç±æ¤å¯ä»¥çåºï¼Tomcatç线ç¨æ± å®ç°æ¯æ¯è¾ç®åçï¼ThreadPool.javaä¹åªæè¡ä»£ç ãç¨ä¸ä¸ªä¸ç»´æ°ç»ä¿å空é²ç线ç¨ï¼æ¯æ¬¡ä»¥ä¸ä¸ªè¾å°æ¥ä¼ï¼5个ï¼å建空é²çº¿ç¨å¹¶æ¾å°çº¿ç¨æ± ä¸ã使ç¨æ¶ä»æ°ç»ä¸ç§»èµ°ç©ºé²ç线ç¨ï¼ç¨å®åï¼åâå½è¿âç»çº¿ç¨æ± ã
java webå¼å ä¼çè¿
å¦æè¿è¡Webå¼åï¼å ¨é¨ç¨JSPåJavaæ¥å®ç°ï¼ä¹æ¯å¯ä»¥çãä½æ¯ä½ ç代ç ä¼é常å¤æï¼å®ç°èµ·æ¥å¾éº»ç¦ï¼ä»ä¹é½æé头åã使ç¨SSHä¸å¤§æ¡æ¶ï¼å ¶å®æ¯æå¾å¤å¥½å¤çãä¼å°è£ å¾å¤å®ç°ï¼ä½ å ·ä½å¼åæ¶ï¼å°±è½æ¯è¾è½»æ¾ãä½æ¯SSHæ¡æ¶é 置对äºåå¦è è¿æ¯æ¯è¾å¤æçã
Strutsçåçåä¼ç¹.
Strutså·¥ä½åç
MVCå³Model-View-Controllerç缩åï¼æ¯ä¸ç§å¸¸ç¨ç设计模å¼ãMVC åå¼±äºä¸å¡é»è¾æ¥å£åæ°æ®æ¥å£ä¹é´çè¦åï¼ä»¥å让è§å¾å±æ´å¯äºååãMVCçå·¥ä½åç,码分flink数据交互源码å¦ä¸å¾1æç¤ºï¼ Struts æ¯MVCçä¸ç§å®ç°ï¼å®å° Servletå JSP æ è®°ï¼å±äº J2EE è§èï¼ç¨ä½å®ç°çä¸é¨åãStruts继æ¿äºMVCçå项ç¹æ§ï¼å¹¶æ ¹æ®J2EEçç¹ç¹ï¼åäºç¸åºçååä¸æ©å±ãStrutsçå·¥ä½åçï¼
è§å¾ï¼ä¸»è¦ç±JSPçæ页é¢å®æè§å¾ï¼Strutsæä¾ä¸°å¯çJSP æ ç¾åºï¼ Htmlï¼Beanï¼Logicï¼Templateçï¼è¿æå©äºåå¼è¡¨ç°é»è¾åç¨åºé»è¾ã
æ§å¶ï¼å¨Strutsä¸ï¼æ¿æ MVCä¸Controllerè§è²çæ¯ä¸ä¸ªServletï¼å«ActionServletãActionServletæ¯ä¸ä¸ªéç¨çæ§å¶ç»ä»¶ãè¿ä¸ªæ§å¶ç»ä»¶æä¾äºå¤çææåéå°StrutsçHTTP请æ±çå ¥å£ç¹ãå®æªååååè¿äºè¯·æ±å°ç¸åºçå¨ä½ç±»ï¼è¿äºå¨ä½ç±»é½æ¯Actionç±»çåç±»ï¼ãå¦å¤æ§å¶ç»ä»¶ä¹è´è´£ç¨ç¸åºç请æ±åæ°å¡«å Action Fromï¼é常称ä¹ä¸ºFromBeanï¼,å¹¶ä¼ ç»å¨ä½ç±»ï¼é常称ä¹ä¸ºActionBeanï¼ãå¨ä½ç±»å®ç°æ ¸å¿åä¸é»è¾ï¼å®å¯ä»¥è®¿é®java bean æè°ç¨EJBãæåå¨ä½ç±»ææ§å¶æä¼ ç»åç»çJSP æ件ï¼åè çæè§å¾ãææè¿äºæ§å¶é»è¾å©ç¨Struts-config.xmlæ件æ¥é ç½®ã
模åï¼æ¨¡å以ä¸ä¸ªæå¤ä¸ªjava beançå½¢å¼åå¨ãè¿äºbeanå为ä¸ç±»ï¼Action FormãActionãJavaBean or EJBãAction Formé常称ä¹ä¸ºFormBeanï¼å°è£ äºæ¥èªäºClientçç¨æ·è¯·æ±ä¿¡æ¯ï¼å¦è¡¨åä¿¡æ¯ãActioné常称ä¹ä¸ºActionBeanï¼è·åä»ActionSevletä¼ æ¥çFormBeanï¼ååºFormBeanä¸çç¸å ³ä¿¡æ¯ï¼å¹¶ååºç¸å ³çå¤çï¼ä¸è¬æ¯è°ç¨Java BeanæEJBçã
æµç¨ï¼å¨Strutsä¸ï¼ç¨æ·ç请æ±ä¸è¬ä»¥*.doä½ä¸ºè¯·æ±æå¡åï¼ææç*.do请æ±å被æåActionSevletï¼ActionSevletæ ¹æ®Struts-config.xmlä¸çé 置信æ¯ï¼å°ç¨æ·è¯·æ±å°è£ æä¸ä¸ªæå®å称çFormBeanï¼å¹¶å°æ¤FormBeanä¼ è³æå®å称çActionBeanï¼ç±ActionBeanå®æç¸åºçä¸å¡æä½ï¼å¦æ件æä½ï¼æ°æ®åºæä½çãæ¯ä¸ä¸ª*.doåæ对åºçFormBeanå称åActionBeanå称ï¼è¿äºå¨Struts-config.xmlä¸é ç½®ã
æ ¸å¿ï¼Strutsçæ ¸å¿æ¯ActionSevletï¼ActionSevletçæ ¸å¿æ¯Struts-config.xmlã
Strutsä¼ç¼ºç¹
ä¼ç¹ï¼ 1. å¼æºè½¯ä»¶ï¼è½æ´æ·±å ¥çäºè§£å ¶å é¨å®ç°æºå¶ã 2.Taglib æ è®°åºï¼çµæ´»å¨ç¨ï¼è½å¤§å¤§æé«å¼åæçã
3.页é¢å¯¼èªä½¿ç³»ç»çèç»æ´å æ¸ æ°ãéè¿ä¸ä¸ªé ç½®æ件ï¼å³å¯ææ¡æ´ä¸ªç³»ç»åé¨åä¹é´çèç³»ï¼è¿å¯¹äºåæçç»´æ¤æçè«å¤§ç好å¤ãå°¤å ¶æ¯å½å¦ä¸æ¹å¼åè æ¥æè¿ä¸ªé¡¹ç®æ¶ï¼è¿ç§ä¼å¿ä½ç°å¾æ´å ææ¾ã
4. æä¾Exceptionå¤çæºå¶ . 5. æ°æ®åºé¾æ¥æ± 管ç
6. Struts çActionå¿ éæ¯threadï¼safeæ¹å¼ï¼å®ä» ä» å 许ä¸ä¸ªå®ä¾å»å¤çææç请æ±ãæ以actionç¨å°çææçèµæºé½å¿ éç»ä¸åæ¥ï¼è¿ä¸ªå°±å¼èµ·äºçº¿ç¨å®å ¨çé®é¢ã 缺ç¹ï¼ Taglib æ¯Strutsçä¸å¤§ä¼å¿ï¼ä½å¯¹äºåå¦è èè¨ï¼å´éè¦ä¸ä¸ªæç»å¦ä¹ çè¿ç¨ï¼çè³è¿ä¼æä¹±ä½ ç½é¡µç¼åçä¹ æ¯ï¼ä½æ¯ï¼å½ä½ ä¹ æ¯äºå®æ¶ï¼ä½ ä¼è§å¾å®ççå¾æ£ã Struts å°MVCçControllerä¸å为ä¸ï¼å¨è·å¾ç»ææ´å æ¸ æ°çåæ¶ï¼ä¹å¢å äºç³»ç»çå¤æ度ã ActionForms 使ç¨ä¸ä¾¿ãæ æ³è¿è¡åå æµè¯ï¼StrutsTestCaseåªè½ç¨äºéæï¼
Springçåçåä¼ç¹
Springçæ£çç²¾åæ¯å®ç Iocæ¨¡å¼ å®ç°çBeanFactoryå AOP ï¼å®èªå·±å¨è¿ä¸ªåºç¡ä¸å»¶ä¼¸çåè½æäºç»è添足ã
Ioc模å¼æ¯ä»ä¹
å¯ä¼¸ç¼©æ§åé/è½»éï¼è°æ¯å®ç¨ç³»ç»çæ¶æ主éï¼
Springå®æ¯ä¸ä¸ªå¼æºç项ç®ï¼èä¸ç®åé常活è·ï¼å®åºäºIoCï¼Inversion of Controlï¼ååæ§å¶ï¼åAOPçææ¶å¤å±j2eeç³»ç»çæ¡æ¶ï¼ä½å®ä¸å¼ºè¿«ä½ å¿ é¡»å¨æ¯ä¸å± ä¸å¿ 须使ç¨Springï¼å 为å®æ¨¡ååçå¾å¥½ï¼å è®¸ä½ æ ¹æ®èªå·±çéè¦éæ©ä½¿ç¨å®çæä¸ä¸ªæ¨¡åï¼å®å®ç°äºå¾ä¼é çMVCï¼å¯¹ä¸åçæ°æ®è®¿é®ææ¯æä¾äºç»ä¸ç æ¥å£ï¼éç¨IoC使å¾å¯ä»¥å¾å®¹æçå®ç°beançè£ é ï¼æä¾äºç®æ´çAOP并æ®æ¤å®ç°Transcation Managmentï¼çç
ä¼ç¹
a. Springè½ææå°ç»ç»ä½ çä¸é´å±å¯¹è±¡ï¼ä¸ç®¡ä½ æ¯å¦éæ©ä½¿ç¨äºEJBãå¦æä½ ä» ä» ä½¿ç¨äºStrutsæå ¶ä»ä¸ºJ2EEç APIç¹å¶çframeworkï¼Springè´åäºè§£å³å©ä¸çé®é¢ã b. Springè½æ¶é¤å¨è®¸å¤å·¥ç¨ä¸å¸¸è§ç对Singletonçè¿å¤ä½¿ç¨ãæ ¹æ®æçç»éªï¼è¿æ¯ä¸ä¸ªå¾å¤§çé®é¢ï¼å®éä½äºç³»ç»çå¯æµè¯æ§åé¢å对象çç¨åº¦ã c. éè¿ä¸ç§å¨ä¸ååºç¨ç¨åºå项ç®é´ä¸è´çæ¹æ³æ¥å¤çé ç½®æ件ï¼Springè½æ¶é¤åç§åæ ·èªå®ä¹æ ¼å¼çå±æ§æ件çéè¦ãæ¾ç»å¯¹æ个类è¦å¯»æ¾çæ¯åªä¸ªéæ³è¬çå±æ§é¡¹æç³»ç»å±æ§æå°ä¸è§£ï¼ä¸ºæ¤ä¸å¾ä¸å»è¯»Javadocçè³æºç¼ç ï¼æäºSpringï¼ä½ ä» ä» éè¦ççç±»çJavaBeanå±æ§ãInversion of Controlç使ç¨ï¼å¨ä¸é¢è®¨è®ºï¼å¸®å©å®æäºè¿ç§ç®åã d.? éè¿æ对æ¥å£ç¼ç¨èä¸æ¯å¯¹ç±»ç¼ç¨ç代价å ä¹åå°å°æ²¡æï¼Springè½å¤ä¿è¿å »æ好çç¼ç¨ä¹ æ¯ã e. Spring被设计为让使ç¨å®å建çåºç¨å°½å¯è½å°çä¾èµäºä»çAPIsãå¨Springåºç¨ä¸ç大å¤æ°ä¸å¡å¯¹è±¡æ²¡æä¾èµäºSpringã f. 使ç¨Springæ建çåºç¨ç¨åºæäºåå æµè¯ã g. Springè½ä½¿EJBç使ç¨æ为ä¸ä¸ªå®ç°éæ©,èä¸æ¯åºç¨æ¶æçå¿ ç¶éæ©ãä½ è½éæ©ç¨POJOsælocal EJBsæ¥å®ç°ä¸å¡æ¥å£ï¼å´ä¸ä¼å½±åè°ç¨ä»£ç ã h. Spring帮å©ä½ 解å³è®¸å¤é®é¢èæ é使ç¨EJBãSpringè½æä¾ä¸ç§EJBçæ¿æ¢ç©ï¼å®ä»¬éç¨äºè®¸å¤webåºç¨ãä¾å¦ï¼Springè½ä½¿ç¨AOPæä¾å£°ææ§äºå¡ç®¡çèä¸éè¿EJB容å¨ï¼å¦æä½ ä» ä» éè¦ä¸å个æ°æ®åºæ交éï¼çè³ä¸éè¦ä¸ä¸ªJTAå®ç°ã i. Spring为æ°æ®ååæä¾äºä¸ä¸ªä¸è´çæ¡æ¶,ä¸è®ºæ¯ä½¿ç¨çæ¯JDBCè¿æ¯O/R mapping产åï¼å¦Hibernateï¼ã Springç¡®å®ä½¿ä½ è½éè¿æç®åå¯è¡ç解å³åæ³æ¥è§£å³ä½ çé®é¢ãèè¿æ¯ææå¾å¤§ä»·å¼çã 缺ç¹ï¼ä½¿ç¨äººæ°ä¸å¤ãjspä¸è¦åå¾å¤ä»£ç ãæ§å¶å¨è¿äºçµæ´»ï¼ç¼ºå°ä¸ä¸ªå ¬ç¨æ§å¶å¨
Hibernateçåçåä¼ç¹ã
Hibernate使ç¨äºJ2EEæ¶æä¸çå¦ä¸ææ¯ï¼JDBCãJTAãJNDIãå ¶ä¸JDBCæ¯ä¸ä¸ªæ¯æå ³ç³»æ°æ®åºæä½çä¸ä¸ªåºç¡å±ï¼å®ä¸JNDIåJTAä¸èµ·ç»åï¼ä½¿å¾Hibernateå¯ä»¥æ¹ä¾¿å°éæå°J2EEåºç¨æå¡å¨ä¸å»ã å¨è¿éï¼æ们ä¸ä¼è¯¦ç»å°å»è®¨è®ºHibernate APIæ¥å£ä¸çæææ¹æ³ï¼æ们åªç®è¦è®²ä¸ä¸æ¯ä¸ªä¸»è¦æ¥å£çåè½ï¼å¦æä½ æ³äºè§£å¾æ´å¤çè¯ï¼ä½ å¯ä»¥å¨Hibernateçæºç å ä¸çnet.sf.hibernateåå ä¸å»æ¥çè¿äºæ¥å£çæºä»£ç ãä¸é¢æ们ä¾æ¬¡è®²ä¸ä¸ææç主è¦æ¥å£ï¼ æ ¸å¿æ¥å£ 以ä¸5ä¸ªæ ¸å¿æ¥å£å ä¹å¨ä»»ä½å®é å¼åä¸é½ä¼ç¨å°ãéè¿è¿äºæ¥å£ï¼ä½ ä¸ä» å¯ä»¥åå¨åè·å¾æä¹ å¯¹è±¡ï¼å¹¶ä¸è½å¤è¿è¡äºå¡æ§å¶ã
Sessionæ¥å£ Sessionæ¥å£å¯¹äºHibernate å¼å人åæ¥è¯´æ¯ä¸ä¸ªæéè¦çæ¥å£ãç¶èå¨Hibernateä¸ï¼å®ä¾åçSessionæ¯ä¸ä¸ªè½»é级çç±»ï¼å建åéæ¯å®é½ä¸ä¼å ç¨å¾å¤èµæºãè¿å¨å®é 项ç®ä¸ç¡®å®å¾éè¦ï¼å 为å¨å®¢æ·ç¨åºä¸ï¼å¯è½ä¼ä¸æå°å建以åéæ¯Session对象ï¼å¦æSessionçå¼é太大ï¼ä¼ç»ç³»ç»å¸¦æ¥ä¸è¯å½±åã
SessionFactory æ¥å£ è¿éç¨å°äºä¸ä¸ªè®¾è®¡æ¨¡å¼ââå·¥å模å¼ï¼ç¨æ·ç¨åºä»å·¥åç±»SessionFactoryä¸åå¾Sessionçå®ä¾ã ä»¤ä½ æå°å¥æªçæ¯SessionFactory并ä¸æ¯è½»é级çï¼å®é ä¸å®ç设计è çæå¾æ¯è®©å®è½å¨æ´ä¸ªåºç¨ä¸å ±äº«ãå ¸åå°æ¥è¯´ï¼ä¸ä¸ªé¡¹ç®é常åªéè¦ä¸ä¸ªSessionFactoryå°±å¤äºï¼ä½æ¯å½ä½ ç项ç®è¦æä½å¤ä¸ªæ°æ®åºæ¶ï¼é£ä½ å¿ é¡»ä¸ºæ¯ä¸ªæ°æ®åºæå®ä¸ä¸ªSessionFactoryã SessionFactoryå¨Hibernateä¸å®é èµ·å°äºä¸ä¸ªç¼å²åºçä½ç¨ï¼å®ç¼å²äºHibernateèªå¨çæçSQLè¯å¥åä¸äºå ¶å®çæ å°æ°æ®ï¼è¿ç¼å²äºä¸äºå°æ¥æå¯è½éå¤å©ç¨çæ°æ®ã
Configuration æ¥å£ Configurationæ¥å£çä½ç¨æ¯å¯¹Hibernateè¿è¡é ç½®ï¼ä»¥å对å®è¿è¡å¯å¨ãå¨Hibernateçå¯å¨è¿ç¨ä¸ï¼Configurationç±»çå®ä¾é¦å å®ä½æ å°ææ¡£çä½ç½®ï¼è¯»åè¿äºé ç½®ï¼ç¶åå建ä¸ä¸ªSessionFactory对象ã
QueryåCriteriaæ¥å£ Queryæ¥å£è®©ä½ æ¹ä¾¿å°å¯¹æ°æ®åºåæä¹ å¯¹è±¡è¿è¡æ¥è¯¢ï¼å®å¯ä»¥æ两ç§è¡¨è¾¾æ¹å¼ï¼HQLè¯è¨ææ¬å°æ°æ®åºçSQLè¯å¥ãQueryç»å¸¸è¢«ç¨æ¥ç»å®æ¥è¯¢åæ°ãéå¶æ¥è¯¢è®°å½æ°éï¼å¹¶æç»æ§è¡æ¥è¯¢æä½ã Criteriaæ¥å£ä¸Queryæ¥å£é常类似ï¼å®å è®¸ä½ å建并æ§è¡é¢å对象çæ ååæ¥è¯¢ã å¼å¾æ³¨æçæ¯Queryæ¥å£ä¹æ¯è½»é级çï¼å®ä¸è½å¨Sessionä¹å¤ä½¿ç¨ã
Callback æ¥å£ å½ä¸äºæç¨çäºä»¶åçæ¶ââä¾å¦æä¹ å¯¹è±¡çè½½å ¥ãåå¨ãå é¤æ¶ï¼Callbackæ¥å£ä¼éç¥Hibernateå»æ¥æ¶ä¸ä¸ªéç¥æ¶æ¯ãä¸è¬èè¨ï¼Callbackæ¥å£å¨ç¨æ·ç¨åºä¸å¹¶ä¸æ¯å¿ é¡»çï¼ä½ä½ è¦å¨ä½ ç项ç®ä¸å建审计æ¥å¿æ¶ï¼ä½ å¯è½ä¼ç¨å°å®ã以ä¸æ¯å®ççç¥æ¥å£ï¼
· 主é®ççæ (IdentifierGenerator æ¥å£)
· æ¬å°SQLè¯è¨æ¯æ (Dialect æ½è±¡ç±»)
· ç¼å²æºå¶ (Cache åCacheProvider æ¥å£)
· JDBC è¿æ¥ç®¡ç (ConnectionProvideræ¥å£)
.äºå¡ç®¡ç (TransactionFactory, Transaction, å TransactionManagerLookup æ¥å£)
· ORM çç¥ (ClassPersister æ¥å£)
· å±æ§è®¿é®çç¥ (PropertyAccessor æ¥å£)
· 代ç对象çå建 (ProxyFactoryæ¥å£)
Hibernate为以ä¸æåçæºå¶åå«å建äºä¸ä¸ªç¼ºççå®ç°ï¼å æ¤å¦æä½ åªæ¯è¦å¢å¼ºå®çæ个çç¥çåè½çè¯ï¼åªéç®åå°ç»§æ¿è¿ä¸ªç±»å°±å¯ä»¥äºï¼æ²¡æå¿ è¦ä»å¤´å¼å§å代ç ã
Hibernateè¿è¡å¨ä¸¤ç§ç¯å¢ä¸ï¼å¯ç®¡çç¯å¢åä¸å¯ç®¡çç¯å¢
· å¯ç®¡çç¯å¢ââè¿ç§ç¯å¢å¯ç®¡çå¦ä¸èµæºï¼æ± èµæºç®¡çï¼è¯¸å¦æ°æ®åºè¿æ¥æ± åï¼è¿æäºå¡ç®¡çãå®å ¨å®ä¹ãä¸äºå ¸åçJ2EEæå¡å¨ï¼JBossãWeblogicãWebSphereï¼å·²ç»å®ç°äºè¿äºã
· ä¸å¯ç®¡çç¯å¢ââåªæ¯æä¾äºä¸äºåºæ¬çåè½ï¼è¯¸å¦åJettyæTomcatè¿æ ·çservlet容å¨ç¯å¢ã
ä¼ç¹ï¼
Hibernateæ¯JDBCçè½»é级ç对象å°è£ ï¼å®æ¯ä¸ä¸ªç¬ç«ç对象æä¹ å±æ¡æ¶ãHibernateå¯ä»¥ç¨å¨ä»»ä½JDBCå¯ä»¥ä½¿ç¨çåºåï¼ä¾å¦Javaåºç¨ç¨åºçæ°æ®åºè®¿é®ä»£ç ï¼DAOæ¥å£çå®ç°ç±»ï¼çè³å¯ä»¥æ¯BMPéé¢ç访é®æ°æ®åºç代ç ã
Hibernateæ¯ä¸ä¸ªåJDBCå¯åå ³èçæ¡æ¶ï¼æ以Hibernateçå ¼å®¹æ§åJDBC驱å¨ï¼åæ°æ®åºé½æä¸å®çå ³ç³»ï¼ä½æ¯å使ç¨å®çJavaç¨åºï¼åApp Server没æä»»ä½å ³ç³»ï¼ä¹ä¸åå¨å ¼å®¹æ§é®é¢ã
Hibernateä¸è½ç¨æ¥ç´æ¥åEntity Beanå对æ¯ï¼åªææ¾å¨æ´ä¸ªJ2EE项ç®çæ¡æ¶ä¸æè½æ¯è¾ã并ä¸å³ä½¿æ¯æ¾å¨è½¯ä»¶æ´ä½æ¡æ¶ä¸æ¥çï¼Hibernateä¹æ¯å为JDBCçæ¿ä»£è åºç°çï¼èä¸æ¯Entity Beançæ¿ä»£è åºç°çï¼
Hibernateæ¯ä¸ä¸ªå¼æ¾æºä»£ç çå¯¹è±¡å ³ç³»æ å°æ¡æ¶ï¼å®å¯¹JDBCè¿è¡äºé常轻é级ç对象å°è£ ï¼ä½¿å¾Javaç¨åºåå¯ä»¥éå¿æ欲ç使ç¨å¯¹è±¡ç¼ç¨æç»´æ¥æ纵æ°æ®åºã
Hibernateå¯ä»¥åºç¨å¨ä»»ä½ä½¿ç¨JDBCçåºåã
Hibernate ä½¿ç¨ Java åå°æºå¶ èä¸æ¯åèç å¢å¼ºç¨åºæ¥å®ç°éææ§ã
Hibernate çæ§è½é常好ï¼å 为å®æ¯ä¸ªè½»é级æ¡æ¶ã æ å°ççµæ´»æ§å¾åºè²ã
å®æ¯æåç§å ³ç³»æ°æ®åºï¼ä»ä¸å¯¹ä¸å°å¤å¯¹å¤çåç§å¤æå ³ç³»ã 缺ç¹ï¼å®éå¶æ¨æ使ç¨ç对象模åã(ä¾å¦ï¼ä¸ä¸ªæä¹ æ§ç±»ä¸è½æ å°å°å¤ä¸ªè¡¨)ã
让æååä¸æ¬¡æå·²ç»ån次çæ¡æ¶ç»æï¼
ä¼ ç»çæ¶æï¼ 1) Session Bean Entity Bean DB
为äºè§£å³æ§è½éç¢çæ¿ä»£æ¶æï¼ 2) Session Bean DAO JDBC DB
使ç¨Hibernateæ¥æé«ä¸é¢æ¶æçå¼åæççæ¶æï¼ 3) Session Bean DAO Hibernate DB
å°±ä¸é¢3个æ¶ææ¥åæï¼ 1 ãå åæ¶èï¼éç¨JDBCçæ¶æ2æ çæ¯æçå åçï¼Hibernateçæ¶æ次ä¹ï¼EBçæ¶æ1æå·®ã 2 ãè¿è¡æçï¼å¦æJDBCç代ç åçé常ä¼åï¼é£ä¹JDBCæ¶æè¿è¡æçæé«ï¼ä½æ¯å®é 项ç®ä¸ï¼è¿ä¸ç¹å ä¹åä¸å°ï¼è¿éè¦ç¨åºåé常精éJDBCï¼è¿ç¨Batchè¯å¥ï¼è°æ´PreapredStatementçBatch SizeåFetch Sizeçåæ°ï¼ä»¥åå¨å¿ è¦çæ åµä¸éç¨ç»æécacheççãèä¸è¬æ åµä¸ç¨åºåæ¯åä¸å°è¿ä¸ç¹çãå æ¤Hibernateæ¶æ表ç°åºæå¿«çè¿è¡æçãEBçæ¶ææçä¼å·®çå¾è¿ã 3 ãå¼åæçï¼å¨æJBuilderçæ¯æä¸ä»¥åç®åç项ç®ï¼EBæ¶æå¼åæçæé«ï¼JDBC次ä¹ï¼Hibernateæå·®ãä½æ¯å¨å¤§ç项ç®ï¼ç¹å«æ¯æä¹ å±å ³ç³»æ å°å¾å¤æçæ åµä¸ï¼Hibernateæçé«çæ人ï¼JDBC次ä¹ï¼èEBæ¶æå¾å¯è½ä¼å¤±è´¥ã