Mybatis插件自动生成mapper.xml和dao

1.pom文件中导入插件jar包

<plugin>
					<groupId>org.mybatis.generator</groupId>
					<artifactId>mybatis-generator-maven-plugin</artifactId>
					<version>1.3.2</version>
					<configuration>
						<verbose>true</verbose>
						<overwrite>true</overwrite>
					</configuration>
				</plugin>

2.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>
    <classPathEntry location="E:/mysql-connector-java-5.1.25.jar" />
    <context id="DB2Tables" targetRuntime="MyBatis3">
      <commentGenerator>
        <property name="suppressAllComments" value="true"/>
      </commentGenerator>
      <jdbcConnection driverClass="com.mysql.jdbc.Driver"
            connectionURL="jdbc:mysql://10.20.22.211:3306/roadassistant"
            userId="root" password="mysql123">
        </jdbcConnection>
      <javaTypeResolver>
         <property name="forceBigDecimals" value="false"/>
      </javaTypeResolver>
      
      <javaModelGenerator targetPackage="com.pingan.insurance.roadassistant.model" targetProject="src/main/java">
          <property name="enableSubPackages" value="true"/>
          <property name="trimStrings" value="true"/>
      </javaModelGenerator>
       
      <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
           <property name="enableSubPackages" value="true"/>
      </sqlMapGenerator>
       
      <javaClientGenerator type="XMLMAPPER" targetPackage="com.pingan.insurance.roadassistant.dao" targetProject="src/main/java">
        <property name="enableSubPackages" value="true"/>
      </javaClientGenerator>
      <table  tableName="rule_condition" domainObjectName="RuleCondition" enableCountByExample="false" enableSelectByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"/>
      <table  tableName="rule_condition_extra" domainObjectName="RuleConditionExtra" enableCountByExample="false" enableSelectByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"/>
      <table  tableName="rule_instance" domainObjectName="RuleInstance" enableCountByExample="false" enableSelectByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"/>
      <table  tableName="rule_operator" domainObjectName="RuleOperator" enableCountByExample="false" enableSelectByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"/>
      <table  tableName="rule_property" domainObjectName="RuleProperty" enableCountByExample="false" enableSelectByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"/>
      <table  tableName="rule_result" domainObjectName="RuleResult" enableCountByExample="false" enableSelectByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"/>
    </context>
      
</generatorConfiguration>

在generatorConfig.xml上右击:Run As-->Run Configurations-->点击项目--->mybatis-generator:generate

 

转载于:https://my.oschina.net/u/3278373/blog/840588

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的 MyBatis Oracle Mapper.xml 示例: ```xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.example.dao.UserDao"> <select id="getUserById" parameterType="int" resultType="com.example.entity.User"> SELECT * FROM users WHERE id = #{id} </select> <insert id="insertUser" parameterType="com.example.entity.User"> INSERT INTO users (name, age) VALUES (#{name}, #{age}) </insert> <update id="updateUser" parameterType="com.example.entity.User"> UPDATE users SET name = #{name}, age = #{age} WHERE id = #{id} </update> <delete id="deleteUser" parameterType="int"> DELETE FROM users WHERE id = #{id} </delete> </mapper> ``` 这个示例包含了四个 SQL 操作,分别是通过 `id` 获取用户信息、插入用户信息、更新用户信息和删除用户信息。这些操作都是通过 SQL 语句来实现的。 在 MyBatis 中,每个 Mapper.xml 文件都定义了一个 namespace,这个 namespace 用于在应用程序中唯一标识这个 Mapper.xml 文件对应的 DAO 接口。在这个示例中,namespace 是 `com.example.dao.UserDao`。 每个操作都有一个唯一的 `id`,这个 `id` 用于在代码中唯一标识这个操作。`parameterType` 和 `resultType` 分别表示操作的输入参数类型和输出结果类型。在这个示例中,`parameterType` 和 `resultType` 都是 Java 对象类型。 注意,这个示例中的 SQL 语句都是 Oracle 数据库的语法。如果你使用的是其他数据库,你需要根据相应的语法修改这些 SQL 语句。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值