• SSH 项目整合


    SSH整合:spring + springmvc + hibernate

      1.1 生成Maven项目:ar_ssh

      1.2 添加jar包:pom.xml

        与ssm相比,主要添加了spring与hibernate整合的jar包(spring-orm)和test包(spring-test)

    <properties>
              <spring.version>4.2.8.RELEASE</spring.version>
              <hibernate.version>5.2.10.Final</hibernate.version>
          </properties>
      
          <dependencies>
            <!-- 单元测试 -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>
            <!-- 日志处理 -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>1.6.4</version>
            </dependency>
            <!-- Spring -->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aspects</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <!-- hibernate -->
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
                <version>${hibernate.version}</version>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-ehcache</artifactId>
                <version>${hibernate.version}</version>
            </dependency>
            <!-- spring 整合 hibernate -->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-orm</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <!-- MySql -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.32</version>
            </dependency>
            <!-- 连接池 -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>1.0.9</version>
            </dependency>
            <!-- JSP相关 -->
            <dependency>
                <groupId>jstl</groupId>
                <artifactId>jstl</artifactId>
                <version>1.2</version>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.5</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jsp-api</artifactId>
                <version>2.0</version>
                <scope>provided</scope>
            </dependency>
            <!-- Jackson Json处理工具包 -->
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.4.2</version>
            </dependency>
            <!-- 文件处理 -->
            <dependency>
                <groupId>commons-fileupload</groupId>
                <artifactId>commons-fileupload</artifactId>
                <version>1.3.2</version>
            </dependency>
        </dependencies>
        <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
        </build>
    pom.xml

      1.3 创建log4j.properties

      1.4 创建db.properties

      2.1 创建spring的配置文件:

          applicationContext-dao.xml:

            dao层的配置文件:

              加载数据库配置文件和其他配置文件

              数据库连接池

              整合hibernate基本配置(LocalSessionFactoryBean)

              扫描dao包

        <util:properties id="hibernateProperties">
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.format_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
        </util:properties>
    
        <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource"></property>
            <property name="hibernateProperties" ref="hibernateProperties"></property>
            <property name="packagesToScan" value="com.roxy.arrescue.pojo"></property>
            <!-- <property name="mappingDirectoryLocations" value="classpath:com/roxy/arrescue/pojo"></property> -->
        </bean>
        
        <context:component-scan base-package="com.roxy.arrescue.dao" />
    applicationContext-dao.xml

          applicationContext-service.xml(与ssm相同)

              扫描service

              配置事务管理

              通知

              切面

           spring-mvc.xml(与ssm相同)

              扫描controller

              注解驱动

              视图解析器

              静态资源解析

      2.2 生成web.xml

        与ssm相比,这三个配置文件基本相同

      3  与web整合

  • 相关阅读:
    只能输入数字
    js 添加、获取、删除 cookie
    获取一个对象的属性/属性值,以及动态给属性赋值
    自定义注解
    C#快捷方式
    前端乱码
    句法错误#{}, 也会导致的异常 org.apache.ibatis.builder.BuilderException java.lang.StringIndexOutOfBoundsException
    [mybatis重复mapper] Error parsing SQL Mapper Configuration
    [aop报错] Cannot resolve reference to bean 'txPointCut' while setting bean property 'pointcut'
    Java工具安装配置(JDK、MySql、Tomcat、Maven、Idea)
  • 原文地址:https://www.cnblogs.com/roxy/p/7650983.html
Copyright © 2020-2023  润新知