1. 程式人生 > >微信小程式(5)搭建SpringBoot後臺

微信小程式(5)搭建SpringBoot後臺

使用IntelliJ IDEA搭建一個整合SpringBoot的Maven聚合專案

結構如圖                                                                                       

 

  1. 搭建一個Maven專案kolkie-parent作為project容器(刪除src)

    1. kolkie-parent需要引入spring-boot-starter-parent包,這個包相當於預設添加了一些常用配置。(具體作用可以參考maven的spring-boot-starter-parent​的作用

      <?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">
          <modelVersion>4.0.0</modelVersion>
      
          <groupId>xc</groupId>
          <artifactId>kolkie-parent</artifactId>
          <packaging>pom</packaging>
          <version>1.0-SNAPSHOT</version>
      
          <parent>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-parent</artifactId>
              <version>1.5.12.RELEASE</version>
              <relativePath/>
          </parent>
      
          <properties>
              <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
              <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
      	<java.version>1.8</java.version>
          </properties>
      
      </project>

       

  2. 在kolkie-parent(Project)搭建一個Maven元件kolkie-common(Module)

    1. kolkie-common作為基礎元件,需要引入常用的工具類和根據業務需求新增的jar包,可供其他模組使用。

      <?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>kolkie-parent</artifactId>
              <groupId>xc</groupId>
              <version>1.0-SNAPSHOT</version>
          </parent>
          <modelVersion>4.0.0</modelVersion>
      
          <artifactId>kolkie-common</artifactId>
      
          <properties>
              <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
          </properties>
      
          <dependencies>
              <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter</artifactId>
                  <exclusions>
                      <!-- 排除springboot預設的logback日誌框架 -->
                      <exclusion>
                          <groupId>org.springframework.boot</groupId>
                          <artifactId>spring-boot-starter-logging</artifactId>
                      </exclusion>
                  </exclusions>
              </dependency>
      
              <!-- 引入log4j日誌依賴 -->
              <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter-log4j</artifactId>
                  <version>1.3.8.RELEASE</version>
              </dependency>
      
              <!-- 引入spring aop依賴 -->
              <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter-aop</artifactId>
              </dependency>
      
              <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter-web</artifactId>
                  <exclusions>
                  </exclusions>
              </dependency>
      
              <!-- 資源配置 -->
              <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-configuration-processor</artifactId>
                  <optional>true</optional>
              </dependency>
      
              <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter-thymeleaf</artifactId>
              </dependency>
      
              <!-- 阿里開源資料來源 -->
              <dependency>
                  <groupId>com.alibaba</groupId>
                  <artifactId>druid</artifactId>
                  <version>1.1.0</version>
              </dependency>
              <dependency>
                  <groupId>com.alibaba</groupId>
                  <artifactId>druid-spring-boot-starter</artifactId>
                  <version>1.1.0</version>
              </dependency>
      
              <dependency>
                  <groupId>mysql</groupId>
                  <artifactId>mysql-connector-java</artifactId>
                  <version>5.1.41</version>
              </dependency>
      
              <!-- mybatis -->
              <dependency>
                  <groupId>org.mybatis.spring.boot</groupId>
                  <artifactId>mybatis-spring-boot-starter</artifactId>
                  <version>1.3.1</version>
              </dependency>
              <!--mapper -->
              <dependency>
                  <groupId>tk.mybatis</groupId>
                  <artifactId>mapper-spring-boot-starter</artifactId>
                  <version>1.2.4</version>
              </dependency>
              <!--pagehelper -->
              <dependency>
                  <groupId>com.github.pagehelper</groupId>
                  <artifactId>pagehelper-spring-boot-starter</artifactId>
                  <version>1.2.3</version>
              </dependency>
      
              <!-- apache 工具類 -->
              <dependency>
                  <groupId>commons-codec</groupId>
                  <artifactId>commons-codec</artifactId>
                  <version>1.11</version>
              </dependency>
              <dependency>
                  <groupId>org.apache.commons</groupId>
                  <artifactId>commons-lang3</artifactId>
                  <version>3.4</version>
              </dependency>
              <dependency>
                  <groupId>org.apache.commons</groupId>
                  <artifactId>commons-io</artifactId>
                  <version>1.3.2</version>
              </dependency>
      
              <!-- swagger2 配置 -->
              <dependency>
                  <groupId>io.springfox</groupId>
                  <artifactId>springfox-swagger2</artifactId>
                  <version>2.4.0</version>
              </dependency>
              <dependency>
                  <groupId>io.springfox</groupId>
                  <artifactId>springfox-swagger-ui</artifactId>
                  <version>2.4.0</version>
              </dependency>
      
              <!-- 引入 redis 依賴 -->
              <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter-data-redis</artifactId>
              </dependency>
              <dependency>
                  <groupId>redis.clients</groupId>
                  <artifactId>jedis</artifactId>
                  <version>2.9.0</version>
              </dependency>
              <dependency>
                  <groupId>org.springframework.data</groupId>
                  <artifactId>spring-data-redis</artifactId>
                  <version>1.8.7.RELEASE</version>
              </dependency>
      
              <!-- 引入zookeeper -->
              <dependency>
                  <groupId>org.apache.curator</groupId>
                  <artifactId>curator-framework</artifactId>
                  <version>4.0.0</version>
              </dependency>
              <dependency>
                  <groupId>org.apache.zookeeper</groupId>
                  <artifactId>zookeeper</artifactId>
                  <version>3.4.11</version>
              </dependency>
              <dependency>
                  <groupId>org.apache.curator</groupId>
                  <artifactId>curator-recipes</artifactId>
                  <version>4.0.0</version>
              </dependency>
      
          </dependencies>
      
      </project>

       

  3. 在kolkie-parent(Project)搭建一個Maven元件kolkie-pojo(Module)

    1. 用於實體類 ,需要依賴kolkie-common元件。

      <?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>kolkie-parent</artifactId>
              <groupId>xc</groupId>
              <version>1.0-SNAPSHOT</version>
          </parent>
          <modelVersion>4.0.0</modelVersion>
      
          <artifactId>kolkie-pojo</artifactId>
      
          <dependencies>
              <dependency>
                  <groupId>xc</groupId>
                  <artifactId>kolkie-common</artifactId>
                  <version>1.0-SNAPSHOT</version>
              </dependency>
              <dependency>
                  <groupId>com.fasterxml.jackson.core</groupId>
                  <artifactId>jackson-annotations</artifactId>
                  <version>2.8.4</version>
                  <scope>compile</scope>
              </dependency>
          </dependencies>
      
      </project>

       

  4. 在kolkie-parent(Project)搭建一個Maven元件kolkie-mapper(Module),並繼承Kolkie-pojo元件

    1. 用於資料庫相關的基本抽象方法的模組 ,需要依賴kolkie-pojo元件。

      <?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>kolkie-parent</artifactId>
              <groupId>xc</groupId>
              <version>1.0-SNAPSHOT</version>
          </parent>
          <modelVersion>4.0.0</modelVersion>
      
          <artifactId>kolkie-mapper</artifactId>
      
          <dependencies>
              <dependency>
                  <groupId>xc</groupId>
                  <artifactId>kolkie-pojo</artifactId>
                  <version>1.0-SNAPSHOT</version>
              </dependency>
          </dependencies>
      
      </project>

       

  5. 在kolkie-parent(Project)搭建一個Maven元件kolkie-service(Module),並繼承Kolkie-mapper元件

    1. 用於業務層程式碼,需要依賴kolkie-mapper元件。

      <?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>kolkie-parent</artifactId>
              <groupId>xc</groupId>
              <version>1.0-SNAPSHOT</version>
          </parent>
          <modelVersion>4.0.0</modelVersion>
      
          <artifactId>kolkie-service</artifactId>
      
          <dependencies>
              <dependency>
                  <groupId>xc</groupId>
                  <artifactId>kolkie-mapper</artifactId>
                  <version>1.0-SNAPSHOT</version>
              </dependency>
          </dependencies>
      
      </project>

       

  6. 在kolkie-parent(Project)搭建一個Maven元件kolkie-api(Module),並繼承Kolkie-mapper元件

    1. 用於前端呼叫的api元件,需要依賴kolkie-service元件。

      <?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>kolkie-parent</artifactId>
              <groupId>xc</groupId>
              <version>1.0-SNAPSHOT</version>
          </parent>
          <modelVersion>4.0.0</modelVersion>
      
          <artifactId>kolkie-mini-api</artifactId>
      
          <dependencies>
              <dependency>
                  <groupId>xc</groupId>
                  <artifactId>kolkie-service</artifactId>
                  <version>1.0-SNAPSHOT</version>
              </dependency>
          </dependencies>
      
      </project>

       

    2. 至此  基本結構搭建完成,另外需要根據具體業務新增程式碼