前言
整合时间2015-8-11 16:18:11,对于之前或者之后的读者,包括我自己请注意整合时间。如果时间过长就放弃往下看吧,浪费时间。第一次写博客,主要是因为我现在没有归类信息,想从博客分类开始,方便自己与初学者。
一、利用maven插件mybatis-generator-maven-plugin编写mybatis对象文件
本次用到的IDE工具为IntelliJidea,主要是因为最近,它太火了,没办法我也试试,一直用Eclipse的同学可能跟着我了解了解它的快捷。。。。开始了
(1)新建一个maven webapp项目
第一次创建的时候我选择这个,累死了,因为这个是直接从maven上载骨架,记住去开源中国配置maven项目仓库,公司自己有的就算求。
开源中国maven仓库:http://maven.oschina.net/home.html
----接下来创建项目的group和ArtifactId,如果你不选择Parent的话,就是单独的项目。本文就直接建立单独的项目开始,毕竟是demo
testsrping
---接下来建立的module名称,其实就是你项目的名称(idea里面module就是项目的意思)
-----------------maven项目就如此简单
项目搭建完毕,不要慌张:
还有附加步骤
复制webapp到main下面
现在才构建完毕,因为没有选择
(1)创建generator的maven插件
进入我们pom的文件
<build>
<plugins>
<!--generator-mybatis插件-->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<span style="white-space:pre"> </span><!--此为generator配置文件路径-->
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
构造配置文件generatorConfig.xml
</pre><pre name="code" class="html"><?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:/mysql-connector-java-5.1.31.jar"/>
<context id="my" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="false"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/ycydb" userId="root"
password="123456"/>
<!-- 生成模型的包名和位置 -->
<javaModelGenerator targetPackage="com.ycy.model"
targetProject="D:/ideaProjects/ycyprivate/springmvc/src/main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- 生成的映射文件包名和位置:特别注意这里,因为idea必须读取resources下面的文件,除非写maven控件(不建议) -->
<sqlMapGenerator targetPackage="mapping"
targetProject="D:/ideaProjects/springmvc/src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- 生成DAO的包名和位置 -->
<javaClientGenerator targetPackage="com.ycy.dao"
targetProject="D:/ideaProjects/ycyprivate/springmvc/src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 要生成那些表(更改tableName和domainObjectName就可以) -->
<table tableName="ycy_user" domainObjectName="UserAccount"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
<!--<columnRenamingRule searchString="^D_"
replaceString=""/>-->
</table>
</context>
</generatorConfiguration>
点击生成entity文件
生成文件
项目文件百度分享:http://pan.baidu.com/s/1eQEqYem
版权声明:本文为博主原创文章,未经博主允许不得转载。交流留下qq