您的位置:首页 > 其它

MyBatis逆向工程自动生成实体类和映射文件

2016-05-20 19:09 831 查看
关于Mybatis+Eclipse快速映射成代码如下:

1.附件为mybaits自动生成工具,在mybatis文件夹下的eclipse目录下的features和plugins拷贝

  到eclipse个相应目录覆盖即可完成安装,重启Eclipse。

2.将 mybatorConfig.xml文件放到项目任何目录下。

  文件中5点注意:

        1.<classPathEntry location="D:/mysql-connector-java-5.1.26-bin.jar" />

          其中放的是数据库驱动包的路径。

       

        2.<jdbcConnection driverClass="com.mysql.jdbc.Driver"

            connectionURL="jdbc:mysql://192.168.0.111:3306/SignalDB" userId="market" password="market4sim">

          </jdbcConnection>

    

        3.<javaModelGenerator targetPackage="com.iquant.signal.entity" targetProject="SignalManagement">

            <property name="enableSubPackages" value="true" />

      </javaModelGenerator>

          生成的Model及我们的数据库表对应的一个个对象的路径,这里jar包默认路径下有src/main/java的路径。

          targetProject放的是我们项目的名称

    4.<sqlMapGenerator targetPackage="com.iquant.signal.mappingr" targetProject="SignalManagement">

            <property name="enableSubPackages" value="true" />

      </sqlMapGenerator>

          生成的Mapper文件路径,这里同上面一样(也可以自定义),可以放绝对路径(不介意)。targetProject放的是我们项目的名称

        5.<table tableName="demo_agent" domainObjectName="DemoAgentTest"

            enableInsert="true" enableSelectByPrimaryKey="true"

            enableUpdateByPrimaryKey="true" enableDeleteByPrimaryKey="true"

            enableCountByExample="false" enableUpdateByExample="false"

            enableDeleteByExample="false" enableSelectByExample="false"

            selectByExampleQueryId="false">

      </table>

          这里每生成一次的时候里面没有注释掉的table都会重新生成一次,所以介意生成一个后注释掉。

          tableName对应数据库表名,domainObjectName为对象名。

3. 生成的时候右键点击 mybatorConfig.xml,单击 Generater Mybatis/iBatis...

注:其他地方勿改。

在设计表结构的时候,最好是这样睡“user_name.user_id”,生成的实体类会自动转为“userName.,userId”

点此下载
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: