黑马程序员技术交流社区

标题: 【石家庄】ssh注解开发简单总结 [打印本页]

作者: lsyt    时间: 2017-11-29 10:29
标题: 【石家庄】ssh注解开发简单总结
本帖最后由 小石姐姐 于 2017-11-29 16:20 编辑

## SSH(注解开发)
* 解决缓存问题openSessionInViewFilter(一定要在 Struts2 Filter 前配置)org.springframework.orm.hibernate5
.support.OpenSessionInViewFilter
* struts2的核心过滤器 org.apache.struts2.dispatcher.ng
.filter.StrutsPrepareAndExecuteFilter
* 开启扫描注解
    * context:component-scan base-package="包名"
### spring整合hibernate(由spring来管理hibernate的sessionFactory)
    * 在spring中提供一个localSessionFactory来加载hibernate的配置文件
    * 必须在web.xml中配置spring的ContextLoaderListener
   
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    * 配置连接池com.mchange.v2.c3p0.ComboPooledDataSource
    * 引入db.properties文件
        context:property-placeholder location="classpath:db.properties
    * 配置sessionFactory
        * property
            * dataSource
            * hibernateProperties()
                * prop(key:value)||value(key=value)
            * packagesToScan
                * list
                    * value(实体类包路径)
    * spring整合hibernate后DAO
        * 只需要DAO类继承hibernateDaoSupport,将sessionFactory注入Dao中,提供set方法(super.setSessionFactory(factory))
        * 增删改查 this.getHibernateTemplate().save/delete/update/find*
    * 事务管理
        * 事务管理器    org.springframework.orm.hibernate5
            .HibernateTransactionManager
        * 事务注解驱动 tx:annotation-driven
    * Service
        * 类上的注解
            * @Service("")
            * @Transactional
        * 注入Dao
            * @Autowire @Qualifier @Resource
### spring整合Struts2框架
* jsp页面form action=
    * ${pageContext.request.contextPath}/Action的value
* action
    * 类上的注解
        * @Controller
        * @Scope("prototype")
        * @NameSpace("/")
        * @ParentPackage("struts-default")
    * 注入service属性
        * @Autowire @Qualifier @Resource
    * 方法上的注解
        * @Action(value="jsp中action的value")
            * results={@result(name="",location="路径")}

作者: 尹哈哈哈    时间: 2017-11-29 11:23
支持下楼主
作者: 小石姐姐    时间: 2017-11-29 16:20
必须支持




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2