IDEA使用 mybatis generator 自动生成mapper文件和model文件
IDEA使用 mybatis generator 自动生成mapper文件和model文件在pom.xml 文件中添加mybatis-generator-maven-plugin<!-- mybatis generator 自动生成代码插件 --><plugin><groupId>org.myb...
·
IDEA使用 mybatis generator 自动生成mapper文件和model文件
-
在pom.xml 文件中添加mybatis-generator-maven-plugin
<!-- mybatis generator 自动生成代码插件 --> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.5</version> <configuration> <configurationFile>src/main/resources/myBatisGeneratorConfig.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> <dependencies> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.5</version> </dependency> </dependencies> </plugin>
-
点击图片中红色圈出的按钮,将此mybatis-generator-maven-plugin装载进此项目
-
在resources文件下,添加myBatisGeneratorConfig.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> <!-- 本地数据库驱动程序jar包的全路径 --> <classPathEntry location="D:\WenJian\Maven\maven_rep\mysql\mysql-connector-java/5.1.44/mysql-connector-java-5.1.44.jar"/> <context id="context" targetRuntime="MyBatis3"> <!--定义生成的java类的编码格式--> <property name="javaFileEncoding" value="UTF-8" /> <!-- 数据库的相关配置 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/whqbs" userId="root" password="qwertyuiop"/> <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal --> <javaTypeResolver> <property name="forceBigDecimals" value="false"/> </javaTypeResolver> <!-- 实体类生成的位置 --> <javaModelGenerator targetPackage="com.tit.springbootdemo01.model" targetProject="src/main/java"> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- *Mapper.xml 文件的位置 --> <sqlMapGenerator targetPackage="com.tit.springbootdemo01.mapper" targetProject="src/main/java"> </sqlMapGenerator> <!-- Mapper 接口文件的位置 --> <javaClientGenerator targetPackage="com.tit.springbootdemo01.mapper" targetProject="src/main/java" type="XMLMAPPER"> </javaClientGenerator> <!-- 相关表的配置 tableName 表名 --> <table tableName="userinfo" enableSelectByExample="true" enableDeleteByExample="true" enableCountByExample="true" enableUpdateByExample="true" selectByExampleQueryId="true"> <property name="ignoreQualifiersAtRuntime" value="false" /> <property name="useActualColumnNames" value="false" /> </table> <table tableName="orgdepartment" enableSelectByExample="true" enableDeleteByExample="true" enableCountByExample="true" enableUpdateByExample="true" selectByExampleQueryId="true"> <property name="ignoreQualifiersAtRuntime" value="false"/> <property name="useActualColumnNames" value="false"/> </table> <table tableName="user" enableSelectByExample="true" enableDeleteByExample="true" enableCountByExample="true" enableUpdateByExample="true" selectByExampleQueryId="true"> <property name="ignoreQualifiersAtRuntime" value="false"/> <property name="useActualColumnNames" value="false"/> </table> <table tableName="logreg" enableSelectByExample="true" enableDeleteByExample="true" enableCountByExample="true" enableUpdateByExample="true" selectByExampleQueryId="true"> <property name="ignoreQualifiersAtRuntime" value="false"/> <property name="useActualColumnNames" value="false"/> </table> </context> </generatorConfiguration>
更多推荐
已为社区贡献1条内容
所有评论(0)