天天看點

struts+spring+ibatis+velocity整合配置

<!--java鑿滈笩绗竴绡?->

杩欏嚑澶╁浜嗕笅struts+spring+ibatis+velocity鐨勬鏋剁粍鍚堛€傚紕浜嗕釜Blog鐨勫皬绋嬪簭锛屽熀鏈笂绠楀氨绠€鐨勪簡锛岀暐璁頒箣銆傞珮绾х殑涓滀笢杩樺湪瀛︿範涓€傘€傘€?

1銆亀eb.xml鐨勯厤缃?

struts+spring+ibatis+velocity整合配置

<? xml聽version="1.0"聽encoding="UTF-8" ?>

struts+spring+ibatis+velocity整合配置

< web-app聽 xmlns ="http://java.sun.com/xml/ns/javaee"

struts+spring+ibatis+velocity整合配置

聽聽聽聽xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" 聽version ="2.5"

struts+spring+ibatis+velocity整合配置

聽聽聽聽xsi:schemaLocation ="http://java.sun.com/xml/ns/javaee聽聽聽http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 <!-- 聽Spring聽鐨勯厤缃?-->

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < context-param >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < param-name > context </ param-name >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < param-value > /WEB-INF/applicationContext </ param-value >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ context-param >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < servlet >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < servlet-name > context </ servlet-name >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < servlet-class >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽org.springframework.web.context.ContextLoaderServlet

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 </ servlet-class >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < load-on-startup > 1 </ load-on-startup >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ servlet >

struts+spring+ibatis+velocity整合配置

銆€銆€銆€銆€銆€聽 <!-- 聽Struts聽鐨勯厤缃?-->

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < servlet >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < servlet-name > action </ servlet-name >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < servlet-class >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽org.apache.struts.action.ActionServlet

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 </ servlet-class >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < init-param >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < param-name > config </ param-name >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < param-value > /WEB-INF/struts-config.xml </ param-value >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 </ init-param >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < init-param >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < param-name > debug </ param-name >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < param-value > 3 </ param-value >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 </ init-param >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < init-param >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < param-name > detail </ param-name >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < param-value > 3 </ param-value >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 </ init-param >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < load-on-startup > 0 </ load-on-startup >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ servlet >

struts+spring+ibatis+velocity整合配置

銆€銆€銆€銆€銆€聽 <!-- 聽Velocity聽鐨勯厤缃?-->

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < servlet >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < servlet-name > velocity </ servlet-name >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < servlet-class >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽org.apache.velocity.tools.view.servlet.VelocityLayoutServlet

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 </ servlet-class >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < init-param >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < param-name > org.apache.velocity.toolbox </ param-name >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < param-value > /WEB-INF/toolbox.xml </ param-value >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 </ init-param >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < init-param >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < param-name > org.apache.velocity.properties </ param-name >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < param-value > /WEB-INF/velocity.properties </ param-value >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 </ init-param >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < load-on-startup > 2 </ load-on-startup >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ servlet >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < servlet-mapping >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < servlet-name > velocity </ servlet-name >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < url-pattern > *.htm </ url-pattern >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ servlet-mapping >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < servlet-mapping >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < servlet-name > action </ servlet-name >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < url-pattern > *.do </ url-pattern >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ servlet-mapping >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < welcome-file-list >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < welcome-file > pages/index.jsp </ welcome-file >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ welcome-file-list >

struts+spring+ibatis+velocity整合配置

</ web-app >

struts+spring+ibatis+velocity整合配置

2銆乤pplicationContext.xml鐨勯厤缃?

struts+spring+ibatis+velocity整合配置

<? xml聽version="1.0"聽encoding="UTF-8" ?>

struts+spring+ibatis+velocity整合配置

< beans聽 xmlns ="http://www.springframework.org/schema/beans"

struts+spring+ibatis+velocity整合配置

聽聽聽聽xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"

struts+spring+ibatis+velocity整合配置

聽聽聽聽xsi:schemaLocation ="http://www.springframework.org/schema/beans聽http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" >

struts+spring+ibatis+velocity整合配置

銆€銆€銆€銆€ <!-- 鏁版嵁搴撻厤缃?-->

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < bean聽 id ="dataSource"

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽class ="org.springframework.jdbc.datasource.DriverManagerDataSource" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < property聽 name ="driverClassName" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < value > ${JDBC.Driver} </ value >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 </ property >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < property聽 name ="url" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < value > ${JDBC.ConnectionURL} </ value >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 </ property >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < property聽 name ="username" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < value > ${Username} </ value >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 </ property >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < property聽 name ="password" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < value > ${Password} </ value >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 </ property >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ bean >

struts+spring+ibatis+velocity整合配置

銆€銆€銆€ <!-- 涓巌batis鏁村悎 -->

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < bean聽 id ="sqlMapClient"

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽class ="org.springframework.orm.ibatis.SqlMapClientFactoryBean" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < property聽 name ="configLocation" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < value > WEB-INF/sql-map-config.xml </ value >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 </ property >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < property聽 name ="dataSource" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < ref聽 bean ="dataSource" 聽 />

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 </ property >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ bean >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < bean聽 id ="TransactionManager"

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽class ="org.springframework.jdbc.datasource.DataSourceTransactionManager" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < property聽 name ="dataSource" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < ref聽 bean ="dataSource" 聽 />

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 </ property >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ bean >

struts+spring+ibatis+velocity整合配置

銆€銆€銆€銆€銆€ <!-- 鐢ㄦ埛DAO閰嶇疆 -->

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < bean聽 id ="blogDAO"

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽class ="com.renyao.ryblog.DAO.DefaultBlogDAO" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < property聽 name ="sqlMapClient" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < ref聽 local ="sqlMapClient" 聽 />

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 </ property >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ bean >

struts+spring+ibatis+velocity整合配置

</ beans >

3銆乻ql-map-config.xml鐨勯厤缃?

struts+spring+ibatis+velocity整合配置

<? xml聽version="1.0"聽encoding="UTF-8" ?>

struts+spring+ibatis+velocity整合配置

<! DOCTYPE聽sqlMapConfig聽PUBLIC聽"-//iBATIS.com//DTD聽SQL聽Map聽Config聽2.0//EN"聽"http://www.ibatis.com/dtd/sql-map-config-2.dtd" >

struts+spring+ibatis+velocity整合配置

< sqlMapConfig >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < settings聽 cacheModelsEnabled ="true" 聽enhancementEnabled ="true"

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽lazyLoadingEnabled ="true" 聽maxRequests ="32" 聽maxSessions ="10"

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽maxTransactions ="5" 聽useStatementNamespaces ="false" 聽 />

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <!-- 鏄犲皠瀛樻斁sql璇彞鐨剎ml鏂囦歡璧勬簮 -->

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < sqlMap聽 resource ="com/renyao/ryblog/Blog.xml" 聽 />

struts+spring+ibatis+velocity整合配置

</ sqlMapConfig >

4銆乮batis鏄犲皠鏂囦歡瀹炰緥--Blog.xml

struts+spring+ibatis+velocity整合配置

<? xml聽version="1.0"聽encoding="UTF-8" ?>

struts+spring+ibatis+velocity整合配置

<! DOCTYPE聽sqlMap

struts+spring+ibatis+velocity整合配置

PUBLIC聽"-//iBATIS.com//DTD聽SQL聽Map聽2.0//EN"

struts+spring+ibatis+velocity整合配置

"http://www.ibatis.com/dtd/sql-map-2.dtd" >

struts+spring+ibatis+velocity整合配置

< sqlMap聽 namespace ="Blog" >

struts+spring+ibatis+velocity整合配置

銆€銆€銆€銆€ <!-- select,update,insert,delete.聽id鍚嶇敤浜庤闂璧勬簮锛宺esultClass琛ㄧず杈撳嚭绫誨瀷锛宲arameterClass琛ㄧず杈撳叆鍙傛暟 -->

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < select聽 id ="getBlog" 聽resultClass ="com.renyao.ryblog.bean.Blog" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽SELECT聽BID聽as聽bid聽,聽TITLE聽as聽title,聽CONTENT聽as聽content,

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽CREATETIME聽as聽createTime,聽MODIFYTIME聽as聽modifyTime,聽CREATER聽as

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽creator,STATUS聽as聽status聽,ISOPEN聽as聽isOpen聽,PICURL聽as聽picURL

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽FROM聽BLOG聽WHERE聽BID聽=聽#value#

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ select >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < select聽 id ="getBlogByTitle"

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽resultClass ="com.renyao.ryblog.bean.Blog" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽SELECT聽BID聽as聽bid聽,聽TITLE聽as聽title,聽CONTENT聽as聽content,

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽CREATETIME聽as聽createTime,聽MODIFYTIME聽as聽modifyTime,聽CREATER聽as

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽creator,STATUS聽as聽status聽,ISOPEN聽as聽isOpen聽,PICURL聽as聽picURL

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽FROM聽BLOG聽WHERE聽TITLE聽like聽#value#

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ select >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < select聽 id ="getAllBlog" 聽resultClass ="com.renyao.ryblog.bean.Blog" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽SELECT聽BID聽as聽bid聽,聽TITLE聽as聽title,聽CONTENT聽as聽content,

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽CREATETIME聽as聽createTime,聽MODIFYTIME聽as聽modifyTime,聽CREATER聽as

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽creator,STATUS聽as聽status聽,ISOPEN聽as聽isOpen聽,PICURL聽as聽picURL

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽FROM聽BLOG

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ select >

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

聽聽聽聽 < insert聽 id ="insertBlog"

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽parameterClass ="com.renyao.ryblog.bean.Blog" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽INSERT聽INTO聽BLOG(TITLE,CONTENT,CREATETIME,MODIFYTIME)聽values

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽(#title#,聽#content#,聽#createTime#,聽#modifyTime#)

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ insert >

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

聽聽聽聽 < update聽 id ="updateBlog"

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽parameterClass ="com.renyao.ryblog.bean.Blog" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽UPDATE聽BLOG聽SET聽TITLE聽=聽#title#,聽CONTENT=聽#content#,聽MODIFYTIME=

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽#modifyTime#聽WHERE聽BID聽=聽#bid#

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ update >

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

聽聽聽聽 < delete聽 id ="deleteBlog"

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽parameterClass ="java.lang.Integer" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽DELETE聽BLOG聽WHERE聽BID聽=聽#bid#

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ delete >

struts+spring+ibatis+velocity整合配置

</ sqlMap >

5銆乻truts-config.xml閰嶇疆

struts+spring+ibatis+velocity整合配置

<? xml聽version="1.0"聽encoding="UTF-8" ?>

struts+spring+ibatis+velocity整合配置

<! DOCTYPE聽struts-config聽PUBLIC聽"-//Apache聽Software聽Foundation//DTD聽Struts聽Configuration聽1.2//EN"聽"http://struts.apache.org/dtds/struts-config_1_2.dtd" >

struts+spring+ibatis+velocity整合配置

< struts-config >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < data-sources聽 />

struts+spring+ibatis+velocity整合配置

銆€銆€銆€銆€ <!-- 涓昏鏄痜orm-bean涓巃ction-mapping鐨勯厤缃紝鍓嶈€呯敤浜庡瓨鏀捐〃鍗曟彁浜ゅ悗鐨勬暟鎹紝鍚庤€呮寚瀹氬鐞咥ction -->

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < form-beans >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < form-bean聽 name ="blogForm"

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽type ="com.renyao.ryblog.form.BlogForm" 聽 />

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ form-beans >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < global-exceptions聽 />

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < global-forwards >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < forward聽 name ="blog" 聽path ="/pages/blog.do?method=list" ></ forward >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ global-forwards >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < action-mappings >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < action聽 input ="/pages/blog_edit.htm" 聽name ="blogForm"

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽parameter ="method" 聽path ="/pages/blog"

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽type ="com.renyao.ryblog.action.BlogAction" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < forward聽 name ="list" 聽path ="/pages/blog.do?method=list" 聽 />

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < forward聽 name ="success" 聽path ="/pages/blog_list.htm" 聽 />

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < forward聽 name ="view" 聽path ="/pages/blog_detail.htm" 聽 />

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 </ action >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < action聽 input ="/pages/blog_add.htm" 聽name ="blogForm"

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽parameter ="method" 聽path ="/pages/blogadd"

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽type ="com.renyao.ryblog.action.BlogAction" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 < forward聽 name ="list" 聽path ="/pages/blog.do?method=list" 聽 />

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽 </ action >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ action-mappings >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < message-resources

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 parameter ="com.renyao.ryblog.ApplicationResources" 聽 />

struts+spring+ibatis+velocity整合配置

</ struts-config >

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

6銆佹暣鍚坴elocity

灏唚eb.xml涓寚瀹氱殑涓や釜鏂囦歡锛宼oolbox.xml锛寁elocity.properties鏀懼埌鐩稿簲鐨勮礬寰勶紝杩樻湁vm_global_library.vm銆?

velocity.properties鐩稿簲璁劇疆濡備笅

struts+spring+ibatis+velocity整合配置

<!-- directory鎸囧畾杈撳嚭鏂囦歡澶癸紝template鎸囧畾杈撳嚭妯℃澘椤?-->

struts+spring+ibatis+velocity整合配置

velocimacro.library聽=聽/WEB-INF/VM_global_library.vm

struts+spring+ibatis+velocity整合配置

input.encoding=GBK

struts+spring+ibatis+velocity整合配置

output.encoding=GBK

struts+spring+ibatis+velocity整合配置

default.contentType=text/html;聽charset=GBK

struts+spring+ibatis+velocity整合配置

tools.view.servlet.layout.directory=pages聽聽聽

struts+spring+ibatis+velocity整合配置

tools.view.servlet.layout.default.template=default.htm

struts+spring+ibatis+velocity整合配置

toolbox.xml宸ュ叿绠辮缃ず渚?

struts+spring+ibatis+velocity整合配置

<? xml聽version="1.0" ?>

struts+spring+ibatis+velocity整合配置

< toolbox >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < tool >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < key > link </ key >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < scope > request </ scope >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < class > org.apache.velocity.tools.struts.StrutsLinkTool </ class >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ tool >

struts+spring+ibatis+velocity整合配置

</ toolbox >

妯℃澘椤典唬鐮?

struts+spring+ibatis+velocity整合配置

<! DOCTYPE聽HTML聽PUBLIC聽"-//W3C//DTD聽HTML聽4.01聽Transitional//EN" >

struts+spring+ibatis+velocity整合配置

< html >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < head >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < title > Renyao聽Blog </ title >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < meta聽 http-equiv ="keywords" 聽content ="keyword1,keyword2,keyword3" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 < meta聽 http-equiv ="description" 聽content ="this聽is聽my聽page" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽 <!-- <link聽rel="stylesheet"聽type="text/css"聽href="./styles.css" target="_blank" rel="external nofollow" > -->

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽 < base聽 href ="$link.baseRef" >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ head >

struts+spring+ibatis+velocity整合配置

聽聽聽聽 < body >

struts+spring+ibatis+velocity整合配置

聽聽聽聽#parse('pages/header.htm')

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽$screen_content聽

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽#parse('pages/footer.htm')

struts+spring+ibatis+velocity整合配置

聽聽聽聽 </ body >

struts+spring+ibatis+velocity整合配置

</ html >

struts+spring+ibatis+velocity整合配置

7銆佸悗鍙闆疄鐜?

闇€瑕佺紪鍐欑殑鏂囦歡锛欱log.xml,Blog.java,BlogForm.java,BlogAction.java,IBlogDAO.java---DAO鎺ュ彛,DefaultBlogDAO.java---瀹炵幇

鏀矽繘鐨勫湴鏂癸細閫氳繃缁ф壙涓庢帴鍙d紭鍖栦唬鐮佺粨鏋?涓昏浠g爜锛?a.BaseAction.java

struts+spring+ibatis+velocity整合配置

package 聽com.renyao.ryblog.action;

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

import 聽org.apache.struts.action.ActionServlet;

struts+spring+ibatis+velocity整合配置

import 聽org.apache.struts.actions.DispatchAction;

struts+spring+ibatis+velocity整合配置

import 聽org.springframework.context.ApplicationContext;

struts+spring+ibatis+velocity整合配置

import 聽org.springframework.web.context.support.WebApplicationContextUtils;

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

public 聽 class 聽BaseAction聽 extends 聽DispatchAction ... {

struts+spring+ibatis+velocity整合配置

聽聽聽聽private聽ApplicationContext聽ac;

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

聽聽聽聽protected聽Object聽getBean(String聽beanName)...{

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽return聽ac.getBean(beanName);

struts+spring+ibatis+velocity整合配置

聽聽聽聽}

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

聽聽聽聽public聽void聽setServlet(ActionServlet聽actionServlet)...{

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽if(actionServlet!=null)...{

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽super.setServlet(actionServlet);

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽ac=WebApplicationContextUtils.getRequiredWebApplicationContext(actionServlet.getServletContext());

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽}

struts+spring+ibatis+velocity整合配置

聽聽聽聽}

struts+spring+ibatis+velocity整合配置

}

struts+spring+ibatis+velocity整合配置

b.BlogAction.java

struts+spring+ibatis+velocity整合配置

package 聽com.renyao.ryblog.action;

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

import 聽java.sql.Date;

struts+spring+ibatis+velocity整合配置

import 聽javax.servlet.http.HttpServletRequest;

struts+spring+ibatis+velocity整合配置

import 聽javax.servlet.http.HttpServletResponse;

struts+spring+ibatis+velocity整合配置

import 聽org.apache.struts.action.ActionForm;

struts+spring+ibatis+velocity整合配置

import 聽org.apache.struts.action.ActionForward;

struts+spring+ibatis+velocity整合配置

import 聽org.apache.struts.action.ActionMapping;

struts+spring+ibatis+velocity整合配置

import 聽com.renyao.ryblog.DAO.iface.IBlogDAO;

struts+spring+ibatis+velocity整合配置

import 聽com.renyao.ryblog.bean.Blog;

struts+spring+ibatis+velocity整合配置

import 聽com.renyao.ryblog.form.BlogForm;

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

public 聽 class 聽BlogAction聽 extends 聽BaseAction聽 ... {

struts+spring+ibatis+velocity整合配置

聽聽聽聽public聽ActionForward聽list(ActionMapping聽mapping,聽ActionForm聽form,

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽HttpServletRequest聽request,聽HttpServletResponse聽response)聽...{

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽try聽...{

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽request.setAttribute("blogs",聽((IBlogDAO)聽getBean("blogDAO"))

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽.getAllBlog());

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽return聽mapping.findForward("success");

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽}聽catch聽(Exception聽e)聽...{

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽return聽mapping.getInputForward();

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽}

struts+spring+ibatis+velocity整合配置

聽聽聽聽}

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

聽聽聽聽public聽ActionForward聽view(ActionMapping聽mapping,聽ActionForm聽form,

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽HttpServletRequest聽request,聽HttpServletResponse聽response)聽...{

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽int聽bid聽=聽Integer.parseInt(request.getParameter("bid"));

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽Blog聽blog聽=聽((IBlogDAO)聽getBean("blogDAO")).getBlog(bid);

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽request.setAttribute("blog",聽blog);

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽return聽mapping.findForward("view");

struts+spring+ibatis+velocity整合配置

聽聽聽聽}

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

聽聽聽聽public聽ActionForward聽delete(ActionMapping聽mapping,聽ActionForm聽form,

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽HttpServletRequest聽request,聽HttpServletResponse聽response)聽...{

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽int聽bid聽=聽Integer.parseInt(request.getParameter("bid"));

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽((IBlogDAO)聽getBean("blogDAO")).deleteBlog(bid);

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽return聽mapping.findForward("list");

struts+spring+ibatis+velocity整合配置

聽聽聽聽}

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

聽聽聽聽public聽ActionForward聽update(ActionMapping聽mapping,聽ActionForm聽form,

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽HttpServletRequest聽request,聽HttpServletResponse聽response)聽...{

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽int聽bid聽=聽Integer.parseInt(request.getParameter("bid"));

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽Date聽modifyTime聽=聽new聽Date(System.currentTimeMillis());

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽Blog聽blog聽=聽((IBlogDAO)聽getBean("blogDAO")).getBlog(bid);

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽blog.setContent(((BlogForm)form).getContent());

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽blog.setTitle(((BlogForm)form).getTitle());

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽blog.setModifyTime(modifyTime);

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽((IBlogDAO)getBean("blogDAO")).updateBlog(blog);

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽return聽mapping.findForward("list");

struts+spring+ibatis+velocity整合配置

聽聽聽聽}

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

聽聽聽聽public聽ActionForward聽insert(ActionMapping聽mapping,聽ActionForm聽form,

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽聽聽聽聽HttpServletRequest聽request,聽HttpServletResponse聽response)聽...{

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽Blog聽blog聽=聽null;

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽String聽title聽=聽((BlogForm)聽form).getTitle();

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽String聽content聽=聽((BlogForm)聽form).getContent();

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽Date聽date聽=聽new聽Date(System.currentTimeMillis());

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽blog.setContent(content);

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽blog.setTitle(title);

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽blog.setCreateTime(date);

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽blog.setModifyTime(date);

struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽((IBlogDAO)聽getBean("blogDAO")).insertBlog(blog);

struts+spring+ibatis+velocity整合配置
struts+spring+ibatis+velocity整合配置

聽聽聽聽聽聽聽聽return聽mapping.findForward("list");

struts+spring+ibatis+velocity整合配置

聽聽聽聽}

struts+spring+ibatis+velocity整合配置

}