generatorConfig自生成代码 Mybatis

自生成代码不可修改 删除

pom依赖

<!--mybatis-->
		<dependency>
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-starter</artifactId>
			<version>2.1.4</version>
		</dependency>
<?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="base" targetRuntime="MyBatis3" defaultModelType="flat">
        <!-- 生成的Java文件的编码 -->
        <property name="javaFileEncoding" value="UTF-8"/>
        <!-- 格式化java代码 -->
        <property name="javaFormatter" value="org.mybatis.generator.api.dom.DefaultJavaFormatter"/>
        <!-- 格式化XML代码 -->
        <property name="xmlFormatter" value="org.mybatis.generator.api.dom.DefaultXmlFormatter"/>

        <commentGenerator>
            <!-- 是否生成注释代时间戳-->
            <property name="suppressDate" value="true"/>
            <!-- 是否去除自动生成的注释 true:是 : false:-->
            <property name="suppressAllComments" value="false"/>
            <!--生成数据库注释-->
            <property name="addRemarkComments" value="true"/>
        </commentGenerator>
        <jdbcConnection
                connectionURL="jdbc:mysql://localhost:3306/jwt?useSSL=false&amp;characterEncoding=utf8&amp;AllowPublicKeyRetrieval=True"
                driverClass="com.mysql.jdbc.Driver"
                password="root"
                userId="root"/>
        <javaTypeResolver>
            <!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.-->
            <property name="forceBigDecimals" value="true"/>
        </javaTypeResolver>
        <!-- 生成模型的包名和位置
        ${PROJECT_DIR}获取当前项目目录然后继续进行
        -->
        <javaModelGenerator targetPackage="com.ly.jwt.db.entity"
                            targetProject="${PROJECT_DIR}/src/main/java">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!-- 生成映射文件的包名和位置-->
        <sqlMapGenerator targetPackage="com.ly.jwt.db.mappers" targetProject="${PROJECT_DIR}/src/main/java">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!-- 生成DAO接口的包名和位置-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.ly.jwt.db.mapper"
                             targetProject="${PROJECT_DIR}/src/main/java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

        <!--账号表-->
        <table tableName="user_account" domainObjectName="UserAccount"
               enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false">
            <generatedKey column="id" sqlStatement="JDBC"/>
        </table>
        <!--日志表-->
        <table tableName="user_log" domainObjectName="UserLog"
               enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false">
            <generatedKey column="id" sqlStatement="JDBC"/>
        </table>
    </context>
</generatorConfiguration>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于自动生成代码的需求,您可以使用一些代码生成工具或框架来简化开发过程。其中一个常用的工具是 MyBatis Generator,它可以根据数据库表结构自动生成对应的实体类、Mapper接口和XML映射文件。 在使用 MyBatis Generator 时,您需要提供一个包含生成配置的 XML 文件,通常称为 generatorConfig.xml。这个文件指定了要生成的实体类、Mapper接口的包名、生成文件的存放路径等信息。您可以根据自己的需求定制这个配置文件,然后运行 MyBatis Generator 工具即可生成相应的代码。 以下是一个示例的 generatorConfig.xml 配置文件,供您参考: ```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> <!-- 数据库连接配置 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/mydatabase" userId="root" password="123456"> </jdbcConnection> <!-- 生成代码的目标路径 --> <javaModelGenerator targetPackage="com.example.model" targetProject="src/main/java"> </javaModelGenerator> <sqlMapGenerator targetPackage="com.example.mapper" targetProject="src/main/java"> </sqlMapGenerator> <javaClientGenerator targetPackage="com.example.mapper" targetProject="src/main/java" type="XMLMAPPER"> </javaClientGenerator> <!-- 数据库表配置 --> <table schema="mydatabase" tableName="user"> <generatedKey column="id" sqlStatement="JDBC" identity="true"/> </table> </generatorConfiguration> ``` 以上配置文件中,指定了数据库连接信息、生成代码目标路径,以及要生成的表信息(这里以`user`表为例)。您可以根据自己的数据库和表结构修改相关配置。 运行 MyBatis Generator 工具时,将该配置文件作为参数传入即可自动生成代码。 请注意,这只是一个示例配置文件,实际使用时您可能需要根据具体需求进行更详细的配置。另外,还有其他一些类似的代码生成工具可供选择,您可以根据自己的喜好和项目需求进行选择和使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值