使用generator逆向生成POJO和DAO类

(需要注意:生成器生成的实体对象只有属性和设置,获取方法,没有的的toString方法)

第一步:

1:在pom.xml的文件中配置插件插件

<plugins>
  <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>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
    </configuration>
  </plugin>
</plugins>

第二步: 

 2:在Maven的中导入jar包(pom.xml)


第二步:

 3:在xml文件中配置(需要注意的是xml的命名需要为generatorConfig.xml,要不然会显示找不到xml文件路径)

      需要修改的内容一般是:

                  1:生成dao的位置    2:生成entity的位置   3:需要生成的表名及

<?xml version =“1.0” encoding =“UTF-8” ?>
  <!DOCTYPE generatorConfiguration PUBLIC “ -  // mybatis.org//DTD MyBatis Generator Configuration 1.0 // EN”
          “http://mybatis.org/dtd / mybatis  - 发电机-config_1_0.dtd“ >
  <generatorConfiguration>
  < -  classPathEntry:数据库的JDBC驱动 - >
  <classPathEntry
  位置=”d:\ MvnRepo \的MySQL \ MySQL的连接器的Java \ 5.1.34 \ MySQL的- 连接器 -  java-5.1.34.jar“ />
      <context id =”MysqlTables“ targetRuntime =”MyBatis3“ >
  <! - 注意这里面的顺序确定的,不能随变更改 - >


                    

                <! - 自定义的分页插件<plugin type =“com.deppon.foss.module.helloworld.shared.PaginationPlugin”/>  - >
          <! - 可选的(0或1) - >
          <! - 注释生成器- >
  <commentGenerator>
  <! - 是否去除自动生成的注释true:是:false:否 - >
  <property name =“suppressAllComments” value =“true” />
          </ commentGenerator>
  <! - 必须的) - >
          <! - 数据库连接的信息:驱动类,连接地址,用户名,密码 - >
  <jdbcConnection driverClass =“com.mysql.jdbc.Driver”
  connectionURL =“jdbc:mysql:// localhost:3306 / work_attendance “
  userId =”root“ password =”123“ >
         </ jdbcConnection>

                                
                                                                
        <! - 可选的(0或1) - >
          <! - 类型转换器或者加类型解析器 - >
          <! - 默认false,把JDBC DECIMAL和
              NUMERIC类型解析为java.math.BigDecimal  - >
  <javaTypeResolver>
              <property name =“forceBigDecimals” value =“false” />
          </ javaTypeResolver>
  <! - 必须的(1 required) - >
          <! -  java模型生成器 - >
          < ! -  targetProject:自动生成代码的位置 - >
  <javaModelGenerator targetPackage =“com.coder520.work_flow.entity”
  targetProject =“E:\ IDEA-project \ work_Attendance_System \ src \ main \ java”
  >
 <! -         

                                                                TODO enableSubPackages:是否让模式作为包的后缀 - >
  <property name =“enableSubPackages” value =“true” />
  <! - 从数据库返回的值被清理前后的空格 - >
  <property name =“trimStrings” value = “true” />
          </ javaModelGenerator>
  <! - 必须的(1 required) - >
          <! -  map xml生成器 - >
  <sqlMapGenerator targetPackage =“com.coder520.work_flow.dao”
  targetProject =“E:\ IDEA- project \ work_Attendance_System \ src \ main \ java“ >
              <property name =”enableSubPackages“ =”true“ />
                                    
                                                 </ sqlMapGenerator>
  <! - 可选的(0或1) - >
          <! -  mapper或者就是dao接口生成器 - >
  <javaClientGenerator targetPackage =“com.coder520.work_flow.dao”
  targetProject =“E:\ IDEA- project \ work_Attendance_System \ src \ main \ java“
  type =”XMLMAPPER“ >
              <property name =”enableSubPackages“ value =”true“ />
          </ javaClientGenerator>
  <! - 必须的(1 ... N) - >
          <! -  pojo实体生成器 - >
          <! -  tableName:用于自动生成代码的数据库表; domainObjectName:对应于数据库表的javaBean类名 - >
          <! -  schema即数据库名可不写 - >
 <   =“参加”
                                                                          
                domainObjectName =“出席”
  enableInsert =“真” enableCountByExample =“假” enableUpdateByExample =“假” enableDeleteByExample =“假”
  enableSelectByExample =“假” selectByExampleQueryId =“假” >
  <! -字段可选的(0或1)忽略- >
              <! -  <ignoreColumn column =“is_use”/>  - >
              <! -  //无论字段是什么类型,生成的类属性都是varchar。可选的(0或1)测试无效 - >
              <! - <columnOverride column =“city_code”jdbcType =“VARCHAR”/>  - >
  </ table>
          <table tableName =“权限” domainObjectName =“权限”
  enableInsert                                                                    =“false” enableCountByExample =“false” enableUpdateByExample =“false” enableDeleteByExample =“false”
  enableSelectByExample =“false” selectByExampleQueryId =“false” >
  <! - 忽略字段可选的(0或1) - >
              <! -  <ignoreColumn column =“is_use”/>  - >
              <! -  //无论字段是什么类型,生成的类属性都是varchar。可选的(0或1)测试无效 - >
              <! -  <columnOverride column =“city_code” jdbcType =“VARCHAR”/>  - >
  </ table>
      </ context>
  </ generatorConfiguration>                                    

第四步:

   4:需要在Maven的中配置generato工程:

      

第五步:

   选中发电机运行即可


猜你喜欢

转载自blog.csdn.net/qq_36957587/article/details/80686525
今日推荐