项目架构介绍
项目使用的是springboot框架,MySql数据库,liquibase数据库版本管理工具,tk.mybatis统一管理增删改查,mybatis-generator生成dao层/po层/mapper.xml文件,jhipster生成controller及service代码。
这里简单介绍liquibase+tk.mybatis+mybatis-generator结合使用,这样做的好处就是可以快速搭建项目的基本框架。
liquibase管理数据库,当数据库的版本发生变更或者某个表的字段发生改变,不再需要复杂的修改各个层的代码。只需要在liquibase的配置文件中对这个表做出更改,然后执行mvn命令,mybatis-generator就可以根据表的该表对原先的实体类做出对应的修改,说是修改,其实是重新读取表结构,重新生成实体类,覆盖了原先的是体类。
具体配置文件
1. pom.xml
pom文件是此项目的基本,根据pom文件配置了springboot的依赖及liquibase/tk.mybatis/mybatis-generator的插件。
<?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>com.jeep</groupId>
<artifactId>leadsscoring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>prj-jeep-leadsscoring-2018</name>
<description>Jeep Leads Scoring</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.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>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
<tk.mybatis.version>3.3.6</tk.mybatis.version>
</properties>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profiles.active>dev</profiles.active>
<db.driver>com.mysql.jdbc.Driver</db.driver>
<db.url>jdbc:mysql://localhost:3306/leadsscoring?useSSL=false</db.url>
<db.username>root</db.username>
<db.password>root</db.password>
</properties>
</profile>
<profile>
<id>qa</id>
<properties>
<profiles.active>qa</profiles.active>
<db.driver>com.mysql.jdbc.Driver</db.driver>
<db.url>jdbc:mysql://localhost:3306/hsale?useSSL=false</db.url>
<db.username>root</db.username>
<db.password>Pass1234</db.password>
</properties>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId&