步骤:

  1. 创建 Maven 模块

image_2023-03-06-20-43-36

  1. 将其 import 到该模块中

image_2023-03-06-20-44-31

  1. 选择模块

image_2023-03-06-20-44-59

  1. 选择导入为 Maven 项目并 finish

image_2023-03-06-20-45-26

  1. 将 ssm 模块中的 domain 给剪切到 pojo 模块中

image_2023-03-06-20-46-40

  1. 配置 ssm 的 pom 文件,将 pojo 模块的坐标导入到该模块中来使用 domain 层的类

image_2023-03-06-20-48-07

  1. 同样的操作创建 dao 模块后将其导入坐标到 ssm 模块的 pom 中

image_2023-03-06-20-49-10

  1. 在 dao 模块中 dao 层需要使用到 mybatis 和 jdbc 的一些操作还有在 BookDao 中使用到了 Book 实体类,所以我们需要将这些东西都导入到 dao 模块的 pom 中
<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">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.dkx.spring</groupId>
  <artifactId>maven-springssm-dao</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>maven-springssm-dao</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.5.11</version>
    </dependency>
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis-spring</artifactId>
        <version>2.0.6</version>
    </dependency>
    <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <version>8.0.28</version>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid</artifactId>
        <version>1.2.8</version>
    </dependency>
    <dependency>
      <groupId>com.dkx.spring</groupId>
      <artifactId>maven-springssm-pojo</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <includes>
          <include>**/*.properties</include>
          <include>**/*.xml</include>
        </includes>
        <filtering>true</filtering>
      </resource>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.properties</include>
          <include>**/*.xml</include>
        </includes>
        <filtering>true</filtering>
      </resource>
    </resources>
  </build>
</project>
  • 因为依赖关系,先将 pojo 模块下载到本地 mvn Install, 再将 dao 模块进行 Install 然后再对 ssm 模块进行 compile 就不会报错了,否则会报错找不到本地依赖 jar 包