1.首先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>
<context id="mysqlgenerator" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.33.173:33944/autotest_v2?useUnicode=true" userId="autestuser" password="autestpwd">
</jdbcConnection>
<javaModelGenerator targetPackage="com.java.test.testDemo.entity" targetProject="src/main/java">
<property name="constructorBased" value="false" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<javaClientGenerator targetPackage="com.java.test.testDemo.dao" type="XMLMAPPER" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 要映射的表名 -->
<table tableName="t_user" delimitIdentifiers="true">
<!-- 参考 javaModelGenerator 的 constructorBased属性 -->
<property name="constructorBased" value="false" />
<!-- 主键 -->
<generatedKey column="user_id" sqlStatement="JDBC"/>
</table>
<!--<table tableName="t_stf_task" delimitIdentifiers="true">-->
<!--<!– 参考 javaModelGenerator 的 constructorBased属性 –>-->
<!--<property name="constructorBased" value="false" />-->
<!--<!– 主键 –>-->
<!--<generatedKey column="task_seq" sqlStatement="JDBC"/>-->
<!--</table>-->
</context>
</generatorConfiguration>
2.pom.xml文件:
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-jdbc</artifactId>-->
<!--</dependency>-->
<!--运行后注释 -->
<!--<plugin>-->
<!--<groupId>org.mybatis.generator</groupId>-->
<!--<artifactId>mybatis-generator-maven-plugin</artifactId>-->
<!--<version>1.3.2</version>-->
<!--<dependencies>-->
<!--<dependency>-->
<!--<groupId>mysql</groupId>-->
<!--<artifactId>mysql-connector-java</artifactId>-->
<!--<version>5.1.21</version>-->
<!--</dependency>-->
<!--</dependencies>-->
<!--<configuration>-->
<!--<overwrite>true</overwrite>-->
<!--</configuration>-->
<!--</plugin>-->
以上两部分添加后会生成
3.双击运行mybatis-generator:generate即可生成
4.使用时候需要接口在dao中类文件前加
@Mapper注解
/**Controller注解**/ @RestController @RequestMapping("123")
@Autowired private TUserMapper tUserMapper; @RequestMapping(value = "/test",method = RequestMethod.GET)
运行含有这个@SpringBootApplication文件的main方法即可
https://start.spring.io/,springboot搭建项目地址可以直接导出来用
http://springcloud.cc,springcloud文档