SSM超详细整合pom依赖文件

SSM整合POM依赖

  • 项目大纲
    • 导入POM依赖
    • web.xml配置文件
    • dispatcherServlet-service.xml配置文件
    • applicationContext.xml配置文件
    • Mybatis.xml配置文件
    • jdbc-config.properties配置文件
    • Mybatis逆序工程

读书人的事怎么能叫偷呢,顶多算白嫖。
                                     ——项目来自尚硅谷雷神视频

项目大纲

SSM超详细整合pom依赖文件_第1张图片

导入POM依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>SSM</artifactId>
        <groupId>rikc</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>ssm-01</artifactId>

    <!--引入项目依赖-->

    <dependencies>
        <!--spring - springmvc -->
        <!--spring webmvc-->
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.2.5.RELEASE</version>
        </dependency>

        <!--spring jdbc-->
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.2.5.RELEASE</version>
        </dependency>

        <!--spring aspect-->
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-aspects -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>5.2.5.RELEASE</version>
        </dependency>
        <!--Spring单元测试-->
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>5.2.5.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <!--mybatis-->
        <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.6</version>
        </dependency>

        <!--Mybatis整合sring的适配包-->
        <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.2</version>
        </dependency>

        <!--数据库连接池 驱动-->
        <!--c3p0-->
        <!-- https://mvnrepository.com/artifact/c3p0/c3p0 -->
        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.mchange/mchange-commons-java -->
        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>mchange-commons-java</artifactId>
            <version>0.2.15</version>
        </dependency>

        <!--德鲁伊连接池-->
        <!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.2.1</version>
        </dependency>

        <!--数据库驱动-->
        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.40</version>
        </dependency>

        <!--(jstl servlet-api junit)-->
        <!-- https://mvnrepository.com/artifact/jstl/jstl -->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/taglibs/standard -->
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>
        <!--返回JSON字符串的支持-->
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.8</version>
        </dependency>
        <!--JSP303数据校验支持-->
        <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.4.1.Final</version>
        </dependency>
        <!--servlet api-->
        <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api -->
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
		 <!--Junit单元测试-->
        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <!--lombok-->
        <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.12</version>
            <scope>provided</scope>
        </dependency>
        <!--PageHelper分页插件-->
        <!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.1.4</version>
        </dependency>


        <!-- MyBatis逆向工程 -->
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.5</version>
        </dependency>

    </dependencies>
    <build>

        <plugins>

            <!-- 配置MyBatis的逆向工程插件 -->
            <plugin>

                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>

                <configuration>

                    <!--显示生成过程中的详细信息 -->
                    <verbose>true</verbose>

                    <!-- 覆盖上次已经生成的文件 -->
                    <overwrite>true</overwrite>

                </configuration>

            </plugin>

        </plugins>

    </build>
</project>

web.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <!-- 配置Spring的上下文监听器,让Spring IOC容器随着Web项目启动而创建 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- 配置contextConfigLocation全局初始化参数,告诉Spring上下文监听器配置文件的位置和名称 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

    <!-- SpringMVC的前端控制器,用来处理全部的HTTP请求 -->
    <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!-- POST请求中文乱码处理过滤器 放在所有过滤器之前-->
    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>utf-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceRequestEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>forceResponseEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*
    
    
    
        HiddenHttpMethodFilter
        org.springframework.web.filter.HiddenHttpMethodFilter
    
    
        HiddenHttpMethodFilter
        /*
    
    
    
        HttpPutFormContentFilter
        org.springframework.web.filter.HttpPutFormContentFilter
    
    
        HttpPutFormContentFilter
        /*
    

dispatcherServlet-service.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    <!--开启注解组件扫描-->
    <context:component-scan base-package="com.rikc">
        <!--&lt;!&ndash;只扫描控制器&ndash;&gt;-->
        <!--<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>-->
    </context:component-scan>
    <!--配置视图解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
    <!--静态资源扫描组件-->
    <mvc:default-servlet-handler/>
    <!--开启WEB注解扫描组件 映射动态请求地址-->
    <mvc:annotation-driven/>
</beans>

applicationContext.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context 
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx.xsd">
        <!--Spring的配置文件,这里配置和业务逻辑有关的-->
        <!--数据源 事务控制 -->
        <context:component-scan base-package="com.rikc">
            <!--不扫描控制器-->
            <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
        </context:component-scan>
        <!--引入外部文件属性-->
        <context:property-placeholder location="classpath:jdbc-config.properties"/>
        <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
            <property name="driverClassName" value="${jdbc.driverClassName}"/>
            <property name="url" value="${jdbc.url}"/>
            <property name="username" value="${jdbc.username}"/>
            <property name="password" value="   ${jdbc.password}"/>
        </bean>
        <!--整合Mybatis-->
        <bean id="sessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
            <!--指定mybatis的全局文件配置-->
            <property name="configLocation" value="classpath:mybatis.xml"/>
            <property name="dataSource" ref="dataSource"/>
            <property name="mapperLocations" value="classpath:com/rikc/mapper/*.xml"></property>
        </bean>
        <!--配置批量查询的sqlSession-->
        <bean id="sessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
            <constructor-arg name="sqlSessionFactory" ref="sessionFactoryBean"/>
            <constructor-arg name="executorType" value="BATCH"/>
        </bean>
        <!--配置扫描器,将mybatis接口的实现加入到IOC容器中-->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <!--扫描所有Mapper接口的实现,加入到IOC容器中-->
            <property name="basePackage" value="com.rikc.mapper"/>
        </bean>
        <!--============================================================-->


        <!--事务控制-->
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <!--控制住数据源-->
            <property name="dataSource" ref="dataSource"/>
        </bean>
        <!--开启基于注解的事务控制,使用XML配置形式的事务-->
        <aop:config>
            <!--切入点表达式-->
            <aop:pointcut id="txPoint" expression="execution(* com.rikc.service..*(..))"/>
            <!--配置事务增强-->
            <aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/>
        </aop:config>

        <!--配置事务增强-->
        <tx:advice id="txAdvice">
            <tx:attributes>
                <!--所有方法都是事务方法-->
                <tx:method name="*"/>
                <!--以get开头的所有方法-->
                <tx:method name="select*" read-only="true"/>
            </tx:attributes>
        </tx:advice>
</beans>

Mybatis.xml配置文件

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

<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>
    <settings>
        <!--驼峰命名规则-->
        <setting name="mapUnderscoreToCamelCase" value="true"/>
        <!--延迟加载-->
        <setting name="lazyLoadingEnabled" value="true"/>
        <setting name="aggressiveLazyLoading" value="false"/>
    </settings>
    <typeAliases>
        <package name="com.rikc.pojo"/>
    </typeAliases>
    <!-- 配置分页插件 -->
    <plugins>

        <!-- 配置分页插件 interceptor属性指定拦截器的完整类名 -->
        <plugin interceptor="com.github.pagehelper.PageInterceptor">
            <!--分页参数合理化-->
            <property name="reasonable" value="true"/>
        </plugin>

    </plugins>

</configuration>

jdbc-config.properties配置文件

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/myemployees?useSSl=false
jdbc.username=root
jdbc.password=jiejie01
mysql.driver.location=e:\\MavenRepository\\mysql\\mysql-connector-java\\5.1.40\\mysql-connector-java-5.1.40.jar

Mybatis逆序工程

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE generatorConfiguration PUBLIC
        "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >

<generatorConfiguration>

    <!-- (1)加载属性文件 -->
    <properties resource="jdbc-config.properties"></properties>

    <!-- (2)指定MySQL的JDBC驱动jar包的位置 -->
    <classPathEntry location="${mysql.driver.location}"/>

    <context id="context" targetRuntime="MyBatis3">

        <!-- 配置是否生成注释信息 suppressAllComments为true表示不生成注释 -->
        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>

        <!-- (3)配置数据库的连接信息 -->
        <jdbcConnection driverClass="${jdbc.driverClassName}"
                        connectionURL="${jdbc.url}"
                        userId="${jdbc.username}"
                        password="${jdbc.password}"/>

        <!-- 配置类型解析器
           value属性默认为false,将JDBC的DECIMAL和NUMERIC类型解析为java.lang.Integer类型
           否则会解析为java.math.BigDecimal类型 -->
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <!-- (4)配置Java实体类的生成位置 -->
        <javaModelGenerator targetPackage="com.rikc.pojo"
                            targetProject="src/main/java">
        </javaModelGenerator>

        <!-- (5)配置SQL映射文件的生成位置 -->
        <sqlMapGenerator targetPackage="com.rikc.mapper"
                         targetProject="src/main/resources">
        </sqlMapGenerator>

        <!-- (6)配置Mapper接口的生成位置 -->
        <javaClientGenerator targetPackage="com.rikc.mapper"
                             type="XMLMAPPER"
                             targetProject="src/main/java">
        </javaClientGenerator>

        <!-- (7)指定根据哪些数据表生成代码 enableXXXByExample表示是否生成QBE风格的查询类 -->
        <table tableName="tbl_emp"
               enableCountByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" enableUpdateByExample="false"/>
        <table tableName="tnl_dept"
               enableCountByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" enableUpdateByExample="false"/>


    </context>

</generatorConfiguration>

你可能感兴趣的:(Spring,Java,SSM,ssm,java,spring,mybatis,web.xml)