liquibase管理数据库与tk.mybatis、mybatis-generator结合使用快速生成代码

本文介绍了如何在springboot项目中结合liquibase进行数据库管理,tk.mybatis实现CRUD,以及mybatis-generator自动生成代码。通过配置pom.xml、application.yml、liquibase和mybatis-generator的相关文件,实现数据库变更与代码同步,简化项目初始化工作。
摘要由CSDN通过智能技术生成

项目架构介绍

项目使用的是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&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值