idea使用mybatis-generator插件自动生成eitity,dao,mapper

一、maven项目的使用方式

1、生成文件的最终结果如下

2、pom generator插件的配置

3、generatorConfig的配置

<?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="D:\Java\repository\mysql\mysql-connector-java\5.1.36\mysql-connector-java-5.1.36.jar" />
   <context id="context1" targetRuntime="MyBatis3">
      <plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin">
         <property name="searchString" value="Example" />
         <property name="replaceString" value="Criteria" />
      </plugin>
      <plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
     
      <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://xxx:3306/xx?useUnicode=true&amp;characterEncoding=UTF-8" userId="xxx" password="xxx" />
      <!-- 此处是将Example改名为Criteria 当然 想改成什么都行 -->

      <!--DTO的路径 -->
      <javaModelGenerator targetPackage="com.xxx.model" targetProject="src/main/java">
         <property name="enableSubPackages" value="true" />
         <property name="trimStrings" value="true" />
      </javaModelGenerator>
      <!--生成SQL-XML的路径 -->
      <sqlMapGenerator targetPackage="mapper.xxx" targetProject="src/main/resources">
         <property name="enableSubPackages" value="true" />
      </sqlMapGenerator>
      <!--DAO的路径 -->
      <javaClientGenerator targetPackage="com.xxx.dao" targetProject="src/main/java" type="XMLMAPPER">
         <property name="enableSubPackages" value="true" />
      </javaClientGenerator>

      <table tableName="t_test" domainObjectName="TestValue">
         <generatedKey column="id" sqlStatement="MySql" identity="true" />
      </table>

   </context>
</generatorConfiguration>

4、运行插件生成配置文件


相关连接:

http://blog.csdn.net/mynamepg/article/details/79414871

http://blog.csdn.net/mynamepg/article/details/79414948


面向对象查询Criteria:

示例1, 查询列表:

ConnPersonDepartCriteria query = new ConnPersonDepartCriteria();
ConnPersonDepartCriteria.Criteria critria = query.createCriteria();
critria.andCompanyIdEqualTo(company);
if(department != null) critria.andDepartIdEqualTo(department);
query.setOrderByClause("person_id desc");
List<ConnPersonDepart> list = connPersonDepartMapper.selectByExample(query);

示例2,统计:

ConnPersonDepartCriteria query = new ConnPersonDepartCriteria();

query.createCriteria().andCompanyIdEqualTo(company).andDepartIdEqualTo(department);
return connPersonDepartMapper.countByExample(query);
示例3, 删除:

ConnPersonDepartCriteria query=new ConnPersonDepartCriteria();
query.createCriteria().andCompanyIdEqualTo(companyId);
connPersonDepartMapper.deleteByExample(query);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值