【正文】
ponse 返回 ModelAndView 對(duì)象 null 就可以直接寫到一個(gè)視圖 里, 在 一般情況下 ,一個(gè) ModelAndView 實(shí)例結(jié)合了一個(gè) view 和一個(gè) model Map,包含了 bean name 和通訊對(duì)象 (像命令或者 form,參考數(shù)據(jù)等等 )。 View 名稱是非常高端的配置 , 不是通過 bean name,一個(gè) properties 文件就是通過你自己的 ViewResolver.這個(gè)抽象的 model Map 允許你在視圖層面完成提取 ,沒有任何的爭(zhēng)辯JSP/Velocity 或者其他 ,每一種都可以直接完整使用 .這個(gè) model Map 還可以簡(jiǎn)單得得到適當(dāng)?shù)母袷交瘮?shù)據(jù)的轉(zhuǎn)換 ,像 JSP 請(qǐng)求屬性或者 Velocity 模版模式 . 如果你不想用 Spring的 web MVC, 但是想借用 Spring嫁接 其他的解決方案 ,你可以非常簡(jiǎn)單地通過 Spring 繼承你自己的 web 框架 , 你可以非常簡(jiǎn)單地通過ContextLoaderListener 啟動(dòng)一個(gè) Spring root application context,并且 ,通過 Struts 或者 WebWork 的 action 利用 ServletContext 屬性 (或者 Spring 的helper 方法 )存取它 。 值得注意的是 , 這里沒有任何的 plugins被調(diào)用 ,因此沒有專門的集成 :來自 web 層的視圖 , 你可以簡(jiǎn)單的將 Spring 作為一個(gè)管理application context 實(shí)例入口點(diǎn)的類庫 。 所有你注冊(cè) bean 和 Spring 服務(wù)都可以在不需要 Spring的 web MVC的情況下都可以 輕松掌握 。 Spring不是和 Struts 、WebWork這些應(yīng)用進(jìn)行競(jìng)爭(zhēng) ,它將作為一個(gè)純 web框架應(yīng)用于很多領(lǐng)域 ,因?yàn)樗恍枰渲脭?shù)據(jù)存儲(chǔ)和事務(wù)操作 , 所以 , 你可以利用 Spring 提供的中間層和數(shù)據(jù)存儲(chǔ)層來豐富你的應(yīng)用 ,甚至用 JDBC 或者 Hibernate 進(jìn)行事務(wù)抽象 。 如果 僅僅 聚焦于 web 支持 ,Spring 的一些顯著特點(diǎn)是 清楚分離 :controller,validator,mand object,form object,model object,和 DispatcherServlet,handler mapping vs view resolver 等等強(qiáng)大而且直接的框架和作為 JavaBeans 的應(yīng)用配置 ,包括簡(jiǎn)單的參照和應(yīng)用內(nèi)容 ,例如 ,從 web 控制器到業(yè)務(wù)對(duì)象和數(shù)據(jù)校驗(yàn) 。 適應(yīng)性 ,無論什么樣的控制器你都需要得到代替Action/ActionForm 所做的每件事情的方案 (簡(jiǎn)單 ,命令 ,form,范例 ,多重 action,或者定制一個(gè) ) 重用業(yè)務(wù)邏輯代碼 ,不需要復(fù)制 ,你可以用已經(jīng)有的業(yè) 務(wù)邏輯對(duì)象作為命令或則 form 對(duì)象代替反射特定的 ActionForm 子類 。 可訂制的 綁 定和數(shù)據(jù)校驗(yàn)作為應(yīng)用級(jí)的輸入機(jī)制的錯(cuò)誤校驗(yàn) ,固定日期和數(shù)字 綁 定 ,例如 ,通過手動(dòng)檢查和轉(zhuǎn)換業(yè)務(wù)對(duì)象來替換單個(gè)的 string。可訂制的操作 ,可訂制的視圖方案 :通過 name/value Map靈活的模型傳送 ,用一個(gè)簡(jiǎn)單的方法從簡(jiǎn)單到復(fù)雜操作映射和視圖方案策略 。 以在 J2EE應(yīng)用中非常普遍的用戶登錄過程為例來說明上述體系結(jié)構(gòu)是如何具體運(yùn)用的。登錄的流程非常清晰:用戶從登錄頁面 ,系統(tǒng)對(duì)登錄信息進(jìn)行驗(yàn)證,如 果正確則成功登錄,否則提示相應(yīng)錯(cuò)誤信息 。 在開發(fā)過程中,使用 Eclipse做為開發(fā)環(huán)境,同時(shí)加載了對(duì) Struts、 Spring及 Hibernate提供更好的控制和支持的第三方插件 MyEclipse, Web服務(wù)器使用 Tomcat, 數(shù)據(jù)庫選用了 Mysql。 首先對(duì) Hibernate進(jìn)行配置,只需要對(duì)系統(tǒng)自動(dòng)生成的,配置好數(shù)據(jù)庫連接的各種參數(shù)以及定義數(shù)據(jù)映射文件。由于 Hibernate所帶的連接池主要用于測(cè)試,性能不是很好,可以通過 JNDI將其修改為使用 Tomcat的連接池。 A Development Frame Application Based on the Hibernate、 the Struts and the Spring J2EE One preface along with the Java technique of gradual mature and perfect. Be establishment business enterprise class application of standard terrace,the J2 EE terrace got substantial of development .Several technique asked for help from to include in the J2 EE norm : Enterprise JavaBean (EJB), Java Servlets (Servlet), Java Server Pages(JSP), Java Message Service(JMS)etc., development many application , also appeared some problem in the tradition J2 the EE the application of the development the process: 1)the antinomy of of data model and logic model. Currently the database of usage basically and all is relation type database, but the Java be essentially a kind of the language which face to object, object at saving with read usage SQL and JDBC carry on a database operation and lowered plait distance of efficiency and system of can maintenance。 2)tradition of J2 EE application much the adoption is according to the EJB heavy weight frame, this kind of frame suitable for develop a large business enterprise application, but usage the EJB container carry on development and adjust to try to need to be waste a great deal of lowering the Ou of code to match sex, exaltation system of development efficiency, this text put forward one kind EE according to the J2 of the Struts frame 、 the Hibernate frame and the Spring frame application development strategy. The Hibernate Frame Data39。s holding out for long time layer and Hibernate is one piece according to hold out for long time layer frame, is a kind of realization object and relation of the tool which reflect to shoot(O/R Mapping), it carried on the object of the lightweight to pack to the JDBC and make procedure member can usage object plait distance thought to operation database. It not only provided to shoot from Java to reflect of data form, but also provided a data a search and instauration mechanism. Opposite in usage JDBC and SQL to operation database, use Hibernate ability consumedly of exaltation realization of efficiency. The Hibernate frame use allocation document of the form e to the reflect of the definition Java object and data form to shoot relation, in the meantime at more deep of level of data form of relation explanation for the relations such as inherit of and containment etc. of Java object. Pass the usage HQL language sentence plications of relation the calculate way use the way of object description, to a large extent simplification logarithms according to of search, speed development of efficiency.