SSM------------MAVEN项目配置

 

edu-manager - 公司员工

edu-student - 学生员工

edu-customer - 客户员工

edu-api

 

项目构造

Jdk1.8

Tomcat8.5

Mysql5.7

SSM

Spring 4.x 版本

MyBatis 3.x 版本

 

 

1》更改IDEA-Maven的用户配置文件

 

2》创建一个空白项目

 

项目名就叫 【教育培训项目】

 

3》创建父工程

 

 

 

 

 

 

4》创建model子工程

 

 

 

 

5》创建dao子工程

6》创建service子工程

7》创建Manager后台管理

 

 

8》在parent中抽取公共的依赖

 

9》Manager中先集成SpringMVC

<dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-test</artifactId>

    <version>${spring.version}</version>

  </dependency>

  <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-core</artifactId>

    <version>${spring.version}</version>

  </dependency>

  <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-oxm</artifactId>

    <version>${spring.version}</version>

  </dependency>

  <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-tx</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-aop</artifactId>

    <version>${spring.version}</version>

  </dependency>

  <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-context</artifactId>

    <version>${spring.version}</version>

  </dependency>

  <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-context-support</artifactId>

    <version>${spring.version}</version>

  </dependency>

  <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-expression</artifactId>

    <version>${spring.version}</version>

  </dependency>

  <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-orm</artifactId>

    <version>${spring.version}</version>

  </dependency>

  <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-web</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-aspects</artifactId>

    <version>${spring.version}</version>

  </dependency>

 

 

把版本信息放在父工程中

 

10》Tomcat跑工程

 

 

11》添加SpringMVC配置文件

Springmvc

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

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

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

       xmlns:mvc="http://www.springframework.org/schema/mvc"

       xmlns:context="http://www.springframework.org/schema/context"

       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"

       xsi:schemaLocation="http://www.springframework.org/schema/beans

      http://www.springframework.org/schema/beans/spring-beans-3.2.xsd

      http://www.springframework.org/schema/mvc

      http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd

      http://www.springframework.org/schema/context

      http://www.springframework.org/schema/context/spring-context-3.2.xsd

      http://www.springframework.org/schema/aop

      http://www.springframework.org/schema/aop/spring-aop-3.2.xsd

      http://www.springframework.org/schema/tx

      http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

  

    <!-- 1.注解扫描位置-->

    <context:component-scan base-package="com.gyf.edu.web.controller" />

  

    <!-- 2.配置映射处理和适配器-->

    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>

    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>

  

    <!-- 3.视图的解析器-->

    <bean

            class="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="prefix" value="/WEB-INF/views/" />

        <property name="suffix" value=".jsp" />

    </bean>

  </beans>

 

 

 

12》在web.xml中加载SpringMVC配置文件

<!-- 配置springmvc-->

  <servlet>

  <servlet-name>DispatcherServlet</servlet-name>

  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

  <init-param>

    <param-name>contextConfigLocation</param-name>

    <param-value>classpath:springmvc.xml</param-value>

  </init-param>

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

  </servlet>

  <servlet-mapping>

  <servlet-name>DispatcherServlet</servlet-name>

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

  </servlet-mapping>

 

 

随便使用一个控制器,看是否springmvc配置成功

13》更改web.xml为3.0

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

  <web-app

        version="3.0"

        xmlns="http://java.sun.com/xml/ns/javaee"

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

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

  

 

 

14》dao-整合mybatis

<dependency>

    <groupId>org.mybatis</groupId>

    <artifactId>mybatis</artifactId>

    <version>${mybatis.version}</version>

  </dependency>

 

<mybatis.version>3.4.1</mybatis.version>

 

添加mybatis依赖

 

添加Mapper公共接口

添加UserMapper.java和xml

 

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

  <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >

  <mapper namespace="com.gyf.edu.mapper.UserMapper" >

  

    <select id="findByID" resultType="user" parameterType="int">

        SELECT * FROM t_user WHERE id = #{id}

    </select>

  </mapper>

 

 

 

15》service依赖dao

service里添加spring的一些依赖

<dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-beans</artifactId>

    <version>${spring.version}</version>

  </dependency>

  <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-context</artifactId>

    <version>${spring.version}</version>

  </dependency>

  <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-tx</artifactId>

    <version>${spring.version}</version>

  </dependency>

 

然后写个UserService,抽取基类

 

 

16》manager依赖 service

 

去除自动检测bean是否存在

 

 

17》Manager 添加其它依赖

Spring+ SpringMVC

MyBatis

Mybatis-spring整合包

AOP联盟+织入

c3p0 数据库连接池

 MySQL连接驱动 + jstl

<properties>

    <junit.version>4.11</junit.version>

    <spring.version>4.3.14.RELEASE</spring.version>

    <mybatis.version>3.4.1</mybatis.version>

    <mybatis-spring.version>1.3.1</mybatis-spring.version>

    <log4j.version>1.2.17</log4j.version>

    <slf4j.version>1.7.12</slf4j.version>

    <jstl.version>1.2</jstl.version>

    <taglibs.version>1.1.2</taglibs.version>

    <c3p0.version>0.9.5.2</c3p0.version>

    <mysql.version>5.1.35</mysql.version>

  </properties>

 

<!-- 数据库驱动 -->

  <dependency>

    <groupId>mysql</groupId>

    <artifactId>mysql-connector-java</artifactId>

    <version>${mysql.version}</version>

  </dependency>

  <!-- 数据连接池 -->

  <dependency>

    <groupId>com.mchange</groupId>

    <artifactId>c3p0</artifactId>

    <version>${c3p0.version}</version>

  </dependency>

  

  <!-- jstl标签类 -->

  <dependency>

    <groupId>jstl</groupId>

    <artifactId>jstl</artifactId>

    <version>${jstl.version}</version>

  </dependency>

  <dependency>

    <groupId>taglibs</groupId>

    <artifactId>standard</artifactId>

    <version>${taglibs.version}</version>

  </dependency>

  <!-- log start -->

  <dependency>

    <groupId>log4j</groupId>

    <artifactId>log4j</artifactId>

    <version>${log4j.version}</version>

  </dependency>

  <dependency>

    <groupId>org.slf4j</groupId>

    <artifactId>slf4j-api</artifactId>

    <version>${slf4j.version}</version>

  </dependency>

  <dependency>

    <groupId>org.slf4j</groupId>

    <artifactId>slf4j-log4j12</artifactId>

    <version>${slf4j.version}</version>

  </dependency>

 

 

18》Manager的其它配置文件

applicationContext,mybatis,log4j,db.properties

 

19》web.xml加载applicationContext.xml配置文件

<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>

 

 

20》在dao打包时要在pom中配置

<plugin>

    <artifactId>maven-resources-plugin</artifactId>

    <version>3.0.2</version>

    <executions>

        <execution>

            <id>copy-xmls</id>

            <phase>process-sources</phase>

            <goals>

                <goal>copy-resources</goal>

            </goals>

            <configuration>

                <outputDirectory>${basedir}/target/classes</outputDirectory>

                <resources>

                    <resource>

                        <directory>${basedir}/src/main/java</directory>

                        <includes>

                            <include>**/*.xml</include>

                        </includes>

                    </resource>

                </resources>

            </configuration>

        </execution>

    </executions>

  </plugin>

 

因为默认情况下.xml不会打包到jar包中

 

21》去除mybatis的配置文件

 

 

  1. 整合页面

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值