美文网首页
搭建通用模块

搭建通用模块

作者: isuntong | 来源:发表于2019-12-19 23:49 被阅读0次

    启动Nexus私服130
    启动gitlab本地托管代码134

    新建群组

    新建目录

    IDEA打开目录

    github新建项目

    手动添加自述文件初始化

    直接提交就行

    拿到SSH地址

    克隆到本地

    克隆不下来,因为我们的docker-compose的yml配置文件中的ip地址为130,需要修改成当前的134

    此时克隆成功

    第一步 创建统一的依赖管理

    项目中添加ignore、attributes文件(从别的项目拷贝过来)

    新建pom.xml文件

    <?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>
    
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.0.6.RELEASE</version>
        </parent>
    
        <groupId>com.suntong</groupId>
        <artifactId>myshop-dependencies</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <packaging>pom</packaging>
    
        <url>http://www.suntong.com</url>
        <inceptionYear>2018-Now</inceptionYear>
    
        <properties>
            <!-- Environment Settings -->
            <java.version>1.8</java.version>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    
            <!-- Spring Boot Starter Settings -->
            <boot-dubbo.version>2.7.0</boot-dubbo.version>
            <boot-mapper.version>2.0.2</boot-mapper.version>
            <boot-pagehelper.version>1.2.5</boot-pagehelper.version>
            <boot-druid.version>1.1.10</boot-druid.version>
    
            <!-- Spring Cloud Settings -->
            <cloud-hystrix.version>2.0.1.RELEASE</cloud-hystrix.version>
    
            <!-- Commons Settings -->
            <kyro.version>0.42</kyro.version>
            <mysql.version>5.7.28</mysql.version>
            <fastdfs.version>1.27</fastdfs.version>
        </properties>
    
        <dependencyManagement>
            <dependencies>
                <!-- Spring Boot Starter Begin -->
                <dependency>
                    <groupId>com.alibaba.boot</groupId>
                    <artifactId>dubbo-spring-boot-starter</artifactId>
                    <version>${boot-dubbo.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.alibaba.boot</groupId>
                    <artifactId>dubbo-spring-boot-actuator</artifactId>
                    <version>${boot-dubbo.version}</version>
                </dependency>
                <dependency>
                    <groupId>tk.mybatis</groupId>
                    <artifactId>mapper-spring-boot-starter</artifactId>
                    <version>${boot-mapper.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.github.pagehelper</groupId>
                    <artifactId>pagehelper-spring-boot-starter</artifactId>
                    <version>${boot-pagehelper.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.alibaba</groupId>
                    <artifactId>druid-spring-boot-starter</artifactId>
                    <version>${boot-druid.version}</version>
                </dependency>
                <!-- Spring Boot Starter End -->
    
                <!-- Spring Cloud Begin -->
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
                    <version>${cloud-hystrix.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
                    <version>${cloud-hystrix.version}</version>
                </dependency>
                <!-- Spring Cloud End -->
    
                <!-- Commons Begin -->
                <dependency>
                    <groupId>de.javakaffee</groupId>
                    <artifactId>kryo-serializers</artifactId>
                    <version>${kyro.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.csource</groupId>
                    <artifactId>fastdfs-client-java</artifactId>
                    <version>${fastdfs.version}</version>
                </dependency>
                <!-- Commons End -->
            </dependencies>
        </dependencyManagement>
    
        <build>
            <plugins>
                <!-- Compiler 插件, 设定 JDK 版本 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <showWarnings>true</showWarnings>
                    </configuration>
                </plugin>
    
                <!-- 打包 jar 文件时,配置 manifest 文件,加入 lib 包的 jar 依赖 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <archive>
                            <addMavenDescriptor>false</addMavenDescriptor>
                        </archive>
                    </configuration>
                    <executions>
                        <execution>
                            <configuration>
                                <archive>
                                    <manifest>
                                        <!-- Add directory entries -->
                                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                                        <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                                        <addClasspath>true</addClasspath>
                                    </manifest>
                                </archive>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    
                <!-- resource -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                </plugin>
    
                <!-- install -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-install-plugin</artifactId>
                </plugin>
    
                <!-- clean -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-clean-plugin</artifactId>
                </plugin>
    
                <!-- ant -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                </plugin>
    
                <!-- dependency -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                </plugin>
            </plugins>
    
            <pluginManagement>
                <plugins>
                    <!-- Java Document Generate -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
    
                    <!-- YUI Compressor (CSS/JS压缩) -->
                    <plugin>
                        <groupId>net.alchim31.maven</groupId>
                        <artifactId>yuicompressor-maven-plugin</artifactId>
                        <version>1.5.1</version>
                        <executions>
                            <execution>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>compress</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <encoding>UTF-8</encoding>
                            <jswarn>false</jswarn>
                            <nosuffix>true</nosuffix>
                            <linebreakpos>30000</linebreakpos>
                            <force>true</force>
                            <includes>
                                <include>**/*.js</include>
                                <include>**/*.css</include>
                            </includes>
                            <excludes>
                                <exclude>**/*.min.js</exclude>
                                <exclude>**/*.min.css</exclude>
                            </excludes>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
    
            <!-- 资源文件配置 -->
            <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <excludes>
                        <exclude>**/*.java</exclude>
                    </excludes>
                </resource>
                <resource>
                    <directory>src/main/resources</directory>
                </resource>
            </resources>
        </build>
    
        <distributionManagement>
            <repository>
                <id>nexus-releases</id>
                <name>Nexus Release Repository</name>
                <url>http://192.168.10.130:8081/repository/maven-releases/</url>
            </repository>
            <snapshotRepository>
                <id>nexus-snapshots</id>
                <name>Nexus Snapshot Repository</name>
                <url>http://192.168.10.130:8081/repository/maven-snapshots/</url>
            </snapshotRepository>
        </distributionManagement>
    
        <repositories>
            <repository>
                <id>nexus</id>
                <name>Nexus Repository</name>
                <url>http://192.168.10.130:8081/repository/maven-public/</url>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
                <releases>
                    <enabled>true</enabled>
                </releases>
            </repository>
    
            <repository>
                <id>aliyun-repos</id>
                <name>Aliyun Repository</name>
                <url>http://maven.aliyun.com/nexus/content/groups/public</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </repository>
    
            <repository>
                <id>sonatype-repos</id>
                <name>Sonatype Repository</name>
                <url>https://oss.sonatype.org/content/groups/public</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>sonatype-repos-s</id>
                <name>Sonatype Repository</name>
                <url>https://oss.sonatype.org/content/repositories/snapshots</url>
                <releases>
                    <enabled>false</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
    
        <pluginRepositories>
            <pluginRepository>
                <id>nexus</id>
                <name>Nexus Plugin Repository</name>
                <url>http://192.168.10.130:8081/repository/maven-public/</url>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
                <releases>
                    <enabled>true</enabled>
                </releases>
            </pluginRepository>
    
            <pluginRepository>
                <id>aliyun-repos</id>
                <name>Aliyun Repository</name>
                <url>http://maven.aliyun.com/nexus/content/groups/public</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    </project>
    

    注意版本问题,到mvn中央仓库中查找版本
    注意最下面私服地址的变化

    在maven管理中增加此项目pom文件

    git提交以下

    第二步 创建通用工具类项目

    新建项目

    添加自述文件

    将项目克隆到本地

    将ignore文件拷贝进来

    新建pom.xml

    <?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>
    
        <parent>
            <groupId>com.suntong</groupId>
            <artifactId>myshop-dependencies</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <relativePath>../myshop-dependencies/pom.xml</relativePath>
        </parent>
    
        <artifactId>myshop-commons</artifactId>
        <packaging>jar</packaging>
    
        <url>http://www.suntong.com</url>
        <inceptionYear>2018-Now</inceptionYear>
    
        <dependencies>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>jcl-over-slf4j</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.hibernate.validator</groupId>
                <artifactId>hibernate-validator</artifactId>
            </dependency>
            <dependency>
                <groupId>org.hibernate.javax.persistence</groupId>
                <artifactId>hibernate-jpa-2.1-api</artifactId>
            </dependency>
    
            <dependency>
                <groupId>de.javakaffee</groupId>
                <artifactId>kryo-serializers</artifactId>
            </dependency>
            <dependency>
                <groupId>com.github.ben-manes.caffeine</groupId>
                <artifactId>guava</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-pool2</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
            </dependency>
        </dependencies>
    </project>
    

    托管到maven

    提交,推送

    第三步 创建通用的领域模型

    创建项目

    添加自述文件

    克隆

    复制ignore文件

    新建pom.xml

    <?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>
    
        <parent>
            <groupId>com.suntong</groupId>
            <artifactId>myshop-dependencies</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <relativePath>../myshop-dependencies/pom.xml</relativePath>
        </parent>
    
        <artifactId>myshop-commons-domain</artifactId>
        <packaging>jar</packaging>
    
        <url>http://www.suntong.com</url>
        <inceptionYear>2018-Now</inceptionYear>
    
        <dependencies>
            <dependency>
                <groupId>com.suntong</groupId>
                <artifactId>myshop-commons</artifactId>
                <version>${project.parent.version}</version>
            </dependency>
        </dependencies>
    </project>
    

    托管到maven

    提交代码

    第四步 创建通用的数据访问

    新建项目

    添加自述文件

    克隆到本地

    复制ignore

    新建pom.xml

    <?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>
    
        <parent>
            <groupId>com.suntong</groupId>
            <artifactId>myshop-dependencies</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <relativePath>../myshop-dependencies/pom.xml</relativePath>
        </parent>
    
        <artifactId>myshop-commons-mapper</artifactId>
        <packaging>jar</packaging>
    
        <url>http://www.suntong.com</url>
        <inceptionYear>2018-Now</inceptionYear>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-redis</artifactId>
            </dependency>
    
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid-spring-boot-starter</artifactId>
            </dependency>
            <dependency>
                <groupId>tk.mybatis</groupId>
                <artifactId>mapper-spring-boot-starter</artifactId>
            </dependency>
            <dependency>
                <groupId>com.github.pagehelper</groupId>
                <artifactId>pagehelper-spring-boot-starter</artifactId>
            </dependency>
    
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <scope>runtime</scope>
            </dependency>
    
            <dependency>
                <groupId>com.suntong</groupId>
                <artifactId>myshop-commons-domain</artifactId>
                <version>${project.parent.version}</version>
            </dependency>
        </dependencies>
    </project>
    

    使用的是tkmybatis

    托管到maven

    新建目录

    修改为源码目录

    提交推送

    注意修改mysql连接依赖版本,配置中修改maven本地仓库位置,修改私服路径

    第五步 创建数据库生成项目

    添加自述文件

    克隆到本地

    复制ignore文件

    新建pom.xml

    <?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>
    
        <parent>
            <groupId>com.suntong</groupId>
            <artifactId>myshop-dependencies</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <relativePath>../myshop-dependencies/pom.xml</relativePath>
        </parent>
    
        <artifactId>myshop-databases</artifactId>
        <packaging>jar</packaging>
    
        <url>http://www.suntong.com</url>
        <inceptionYear>2018-Now</inceptionYear>
    
        <dependencies>
            <dependency>
                <groupId>com.suntong</groupId>
                <artifactId>myshop-commons-mapper</artifactId>
                <version>${project.parent.version}</version>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-maven-plugin</artifactId>
                    <version>1.3.5</version>
                    <configuration>
                        <configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
                        <overwrite>true</overwrite>
                        <verbose>true</verbose>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>mysql</groupId>
                            <artifactId>mysql-connector-java</artifactId>
                            <version>${mysql.version}</version>
                        </dependency>
                        <dependency>
                            <groupId>tk.mybatis</groupId>
                            <artifactId>mapper</artifactId>
                            <version>3.4.4</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    </project>
    

    交给intelliJ托管

    新建源码目录

    创建generatorConfig.xml

    <?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>
        <!-- 引入数据库连接配置 -->
        <properties resource="jdbc.properties"/>
    
        <context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
            <property name="beginningDelimiter" value="`"/>
            <property name="endingDelimiter" value="`"/>
    
            <!-- 配置 tk.mybatis 插件 -->
            <plugin type="tk.mybatis.mapper.generator.MapperPlugin">
                <property name="mappers" value="tk.mybatis.mapper.MyMapper"/>
            </plugin>
    
            <!-- 配置数据库连接 -->
            <jdbcConnection
                    driverClass="${jdbc.driverClass}"
                    connectionURL="${jdbc.connectionURL}"
                    userId="${jdbc.username}"
                    password="${jdbc.password}">
            </jdbcConnection>
    
            <!-- 配置实体类存放路径 -->
            <javaModelGenerator targetPackage="com.suntong.myshop.commons.domain" targetProject="src/main/java"/>
    
            <!-- 配置 XML 存放路径 -->
            <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources"/>
    
            <!-- 配置 DAO 存放路径 -->
            <javaClientGenerator
                    targetPackage="com.suntong.myshop.commons.mapper"
                    targetProject="src/main/java"
                    type="XMLMAPPER"/>
    
            <!-- 配置需要生成的表,% 代表所有 -->
            <table catalog="myshop" tableName="%">
                <!-- mysql 配置 -->
                <generatedKey column="id" sqlStatement="Mysql" identity="true"/>
            </table>
        </context>
    </generatorConfiguration>
    

    新建jdbc.properties

    jdbc.driverClass=com.mysql.jdbc.Driver
    jdbc.connectionURL=jdbc:mysql://192.168.79.135:3306/myshop?useUnicode=true&characterEncoding=utf-8&useSSL=false
    jdbc.username=root
    jdbc.password=123456
    

    注意ip地址,看启动后的虚拟机是什么ip

    双击插件自动生成

    注意先启动虚拟机中的mysql

    发现生成的实体类还是有两个点

    手动删除,嘻嘻

    将domain复制到domain项目中

    将mapper复制到mapper项目中

    将mapper配置文件复制到mapper项目的资源配置文件夹下

    第六步 创建通用静态资源

    新建项目

    添加自述文件

    克隆

    复制过滤配置文件

    新建pom.xml

    <?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>
    
        <parent>
            <groupId>com.suntong</groupId>
            <artifactId>myshop-dependencies</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <relativePath>../myshop-dependencies/pom.xml</relativePath>
        </parent>
    
        <artifactId>myshop-static-backend</artifactId>
        <packaging>jar</packaging>
    
        <url>http://www.suntong.com</url>
        <inceptionYear>2018-Now</inceptionYear>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-thymeleaf</artifactId>
            </dependency>
    
            <dependency>
                <groupId>net.sourceforge.nekohtml</groupId>
                <artifactId>nekohtml</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
            </dependency>
        </dependencies>
    </project>
    

    托管

    创建资源目录

    使用metronic模板

    static目录下新建assets(资源)目录

    将所需资源复制到目录下

    提交代码

    文件较多,提交较慢,耐心等待

    都提交上来了

    电脑风扇吹啊吹啊

    我的内存放纵。。。

    一定及时关掉不用的程序

    相关文章

      网友评论

          本文标题:搭建通用模块

          本文链接:https://www.haomeiwen.com/subject/tyxvnctx.html