框架整合

easyui和struts2

方式1  添加struts2的json插件jar包

    配置文件  package extends=“json-default”

          <action><result type=“json”>  返回action对象的json

                            <paran name=“root”>action对象的属性名</action>  返回action对象的对应属性值

方式2  action类中方法不需要返回值,把json结果使用response返回

    配置文件  action不需要配置result  

          package使用struts-default 

spring和struts2

目的  容器管理action类

步骤  struts2  支持spring的jar包

          配置<action class=“acton类在容器中的ID”>

          action类  定义需要容器注入的属性

    spring  添加支持web的jar包

         修改web.xml  (alt+/,输入c,选择ContextLoaderListener)

                  配置文件的位置和名称  classpath:配置文件名

                  加在容器的监听器

         添加action类的bean  注入action类需要的属性

                    scope=“prototype”(多例模式)

Spring和hibernate

目的  由Spring创建和管理sessionFactory

    使用Spring的声明式事务

步骤  hibernate部分  hibernate.cfg.xml 可有可无

    Spring  添加 jar 包

         配置基于连接池的数据源(一般使用C3P0)(加载外部配置文件)

         创建SessionFactory  class=“Spring的包装类”

                     dataSource-“连接池数据源id”

                     hibernate的配置项  加在原生配置文件(或直接配置)

                     加在映射文件(可以使用通配符*)

         配置声明式事务  事务管理器  关联SessionFactory

                  事务通知<tx:advice>  关联事务管理器

                                配置被通知的方法  <tx:attributes>  

                                            <tx:method name=“方法通配名” readonly=true/>

                                           (只读方法,不进行事务管理)

                  事务切点  <aop:config>  <aop:advisor advice-ref=“事务通知id” pointcut=“切点表达式”>

原文地址:https://www.cnblogs.com/jingfengling/p/6186293.html