maven 依赖配置:
<!-- sql server -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.4</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
构建所需插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
<!-- mybatis generator 自动生成代码插件 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.6.1</version>
</plugin>
</plugins>
<finalName>springboot-test</finalName>
<!-- 指定生成文件存放的目录 -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
<include>application.properties</include>
<include>banner.txt</include>
<include>META-INF/app.properties</include>
<!--<include>application-${profileActive}.properties</include>-->
</includes>
<excludes>
<exclude>generatorConfig.xml</exclude>
</excludes>
</resource>
</resources>
</build>
generatorConfig.xml文件配置,该文件在resource目录下。
<?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>
<!-- 修改成自己本地的maven仓库地址,只需要替换红色部分即可(D:maven epository) -->
<classPathEntry location="D:maven epositorycommicrosoftsqlservermssql-jdbc6.1.0.jre8mssql-jdbc-6.1.0.jre8.jar" />
<context defaultModelType="flat" id="write" targetRuntime="MyBatis3">
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
<plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
<commentGenerator>
<property name="suppressAllComments" value="false"/>
<property name="suppressDate" value="false"/>
</commentGenerator>
<!-- 这里是sqlserver 数据库 -->
<jdbcConnection driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver"
connectionURL="jdbc:sqlserver://ip:1433;DatabaseName=test"
userId="sa"
password="123456">
</jdbcConnection>
<javaTypeResolver>
<property name="trimStrings" value="true" />
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!--生成model 指定生成后类的存放目录-->
<javaModelGenerator targetPackage="com.example.model.po.base.mbg"
targetProject="${generator.path}/src/main/java">
<property name="enableSubPackages" value="true"/>
</javaModelGenerator>
<!--生成xml文件 指定生成后的xml 文件存放的目录-->
<sqlMapGenerator targetPackage="com.example.dal.mappers.base.mbg"
targetProject="${generator.path}/src/main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</sqlMapGenerator>
<!--生成mappers 指定生成 后mappers 接口存放的目录-->
<javaClientGenerator targetPackage="com.example.dal.dao.base.mbg"
targetProject="${generator.path}/src/main/java"
type="XMLMAPPER">
<property name="enableSubPackages" value="true"/>
<property name="exampleMethodVisibility" value="public"/>
<property name="methodNameCalculator" value="default"/>
</javaClientGenerator>
<!-- tableName:指的是你数据库中表的名称;domainObjectName:指的是生成实体类对应的名称 -->
<table tableName="SYS_Menu" domainObjectName="SysMenu" enableSelectByPrimaryKey="true" enableCountByExample="true" enableSelectByExample="true">
<property name="useActualColumnNames" value="true" />
<!-- column:指的是sql语句是否设置自动增长 -->
<generatedKey column="id" identity="true" sqlStatement="SqlServer"/>
</table>
</context>
</generatorConfiguration>