赞
踩
话不多说,直接上代码!!!
build.gradle文件:
plugins { id 'org.springframework.boot' version '2.2.5.RELEASE' id 'io.spring.dependency-management' version '1.0.11.RELEASE' id 'groovy' id 'java' } group 'com.yjq.programmer' version '1.0-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenLocal() maven {url "https://maven.aliyun.com/repository/public"} maven {url "https://maven.aliyun.com/repository/central"} maven {url "https://maven.aliyun.com/repository/google"} maven {url "https://maven.aliyun.com/repository/spring"} mavenCentral() } configurations { mybatisGenerator } dependencies { implementation 'org.springframework.boot:spring-boot-starter' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'mysql:mysql-connector-java:5.1.6' implementation 'com.alibaba:druid:1.1.19' implementation 'com.alibaba:fastjson:1.2.31' implementation 'com.github.pagehelper:pagehelper-spring-boot-starter:1.2.13' implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2' implementation 'org.springframework.boot:spring-boot-starter-data-redis' mybatisGenerator 'org.mybatis.generator:mybatis-generator-maven-plugin:1.3.7' mybatisGenerator 'mysql:mysql-connector-java:5.1.6' compile 'org.codehaus.groovy:groovy-all:2.3.11' testCompile group: 'junit', name: 'junit', version: '4.12' } task mybatisGenerate { ant.taskdef( name: 'mbgenerator', classname: 'org.mybatis.generator.ant.GeneratorAntTask', classpath: configurations.mybatisGenerator.asPath ) ant.mbgenerator(overwrite: true, configfile: 'src/main/resources/generator/generatorConfig.xml', verbose: true) }
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="Mysql" targetRuntime="MyBatis3" defaultModelType="flat"> <property name="autoDelimitKeywords" value="true"/> <!-- 字段加上引号 防止关键字冲突 --> <property name="beginningDelimiter" value="`"/> <property name="endingDelimiter" value="`"/> <!--覆盖生成XML文件--> <plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" /> <!-- 生成的实体类添加toString()方法 --> <plugin type="org.mybatis.generator.plugins.ToStringPlugin" /> <!-- 不生成注释 --> <commentGenerator> <property name="suppressAllComments" value="true"/> </commentGenerator> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/db_library_manage_system" userId="root" password=""> </jdbcConnection> <!-- domain类的位置 --> <javaModelGenerator targetProject="src/main/java" targetPackage="com.yjq.programmer.domain"/> <!-- mapper xml的位置 --> <sqlMapGenerator targetProject="src/main/resources" targetPackage="mapper"/> <!-- dao 类的位置 --> <javaClientGenerator targetProject="src/main/java" targetPackage="com.yjq.programmer.dao" type="XMLMAPPER" /> <table tableName="user" domainObjectName="User"/> </context> </generatorConfiguration>
上述代码配置完后,记得先加载下依赖,然后执行上面配置的那个任务就好了啦。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。