MyBatis Generator 配置
来源:互联网 发布:一彩软件 编辑:程序博客网 时间:2024/05/02 00:01
<build><plugins><plugin> <groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-maven-plugin</artifactId><version>1.3.2</version><executions><execution><id>Generate MyBatis Artifacts</id><goals><goal>generate</goal></goals></execution></executions><configuration><verbose>true</verbose><overwrite>true</overwrite><!-- <jdbcDriver>com.mysql.jdbc.Driver</jdbcDriver> --><!-- <jdbcURL>jdbc:mysql://localhost:3306/xxxx</jdbcURL> --><!-- <jdbcUserId>test</jdbcUserId> --><!-- <jdbcPassword>test</jdbcPassword> --></configuration><dependencies><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.6</version></dependency><dependency><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-core</artifactId><version>1.3.2</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.2.2</version></dependency></dependencies></plugin></plugins></build>
Idea中这么配置就可以了。
重点注意以下几点
如果不再plugin里面添加依赖包得引用的话,会找不到相关得jar包,在plugin外部得jar包,他不会去找到并执行,所以要把plugin运行依赖得jar配置都放在里面
另外generatorConfig.xml里面得targetProject,可以写成src/main/java,也就是Maven管理得编译代码路径,我之前用generator插件右键生成可以写项目名,但是在这里就不好用了。
generatorConfig.xml如果不写路径的话,默认是读取src/main/resource下面得
关于M2E 的Eclipse插件,目前还不支持execution
报如下错误
Plugin execution not covered by lifecycle configuration
官方文档给出的如下
https://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html
修改一下写成如下:
<build><plugins><plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <executions> <execution> <id>Generate MyBatis Artifacts</id> <goals> <goal>generate</goal> </goals> </execution> </executions> <configuration> <verbose>true</verbose> <overwrite>true</overwrite> <!-- <jdbcDriver>com.mysql.jdbc.Driver</jdbcDriver> <jdbcURL>jdbc:mysql://localhost:3306/xxxx</jdbcURL> <jdbcUserId>root</jdbcUserId> <jdbcPassword></jdbcPassword> --> </configuration> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.6</version> </dependency> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.2</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.2.8</version> </dependency> </dependencies> </plugin></plugins> <pluginManagement> <plugins> <plugin> <groupId>org.eclipse.m2e</groupId> <artifactId>lifecycle-mapping</artifactId> <version>1.0.0</version> <configuration> <lifecycleMappingMetadata> <pluginExecutions> <!-- copy-dependency plugin --> <pluginExecution> <pluginExecutionFilter> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <versionRange>[1.0.0,)</versionRange> <goals> <goal>copy-dependencies</goal> </goals> </pluginExecutionFilter> <action> <ignore /> </action> </pluginExecution> <!-- mybatis-generator-plugin --> <pluginExecution> <pluginExecutionFilter> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <versionRange>[1.3.2,)</versionRange> <goals> <goal>generate</goal> </goals> </pluginExecutionFilter> <action> <ignore /> </action> </pluginExecution> </pluginExecutions> </lifecycleMappingMetadata> </configuration> </plugin> </plugins> </pluginManagement> </build>
这样就不会报错了。
再贴上配置文件:
<?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> <properties resource="db.properties" /> <context id="sqlserverTables" targetRuntime="MyBatis3"> <!-- 生成的pojo,将implements Serializable--> <plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin> <commentGenerator> <!-- 是否去除自动生成的注释 true:是 : false:否 --> <property name="suppressAllComments" value="true" /> </commentGenerator> <!-- 数据库链接URL、用户名、密码 --> <jdbcConnection driverClass="${jdbc.driver}" connectionURL="${jdbc.url}" userId="${jdbc.username}" password="${jdbc.password}"> </jdbcConnection> <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer true,把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal --> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 生成model模型,对应的包路径,以及文件存放路径(targetProject),targetProject可以指定具体的路径,如./src/main/java, 也可以使用“MAVEN”来自动生成,这样生成的代码会在target/generatord-source目录下 --> <!--<javaModelGenerator targetPackage="com.xxx.mybaties.test.pojo" targetProject="MAVEN">--> <javaModelGenerator targetPackage="com.xxxx.entity" targetProject="src/main/java"> <property name="enableSubPackages" value="true"/> <!-- 从数据库返回的值被清理前后的空格 --> <property name="trimStrings" value="true" /> </javaModelGenerator> <!--对应的mapper.xml文件 --> <sqlMapGenerator targetPackage="com.xxxx.mapping" targetProject="src/main/java"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <!-- 对应的Mapper接口类文件 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.xxxx.mapper" targetProject="src/main/java"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <!-- 列出要生成代码的所有表,这里配置的是不生成Example文件 --> <table tableName="xxx" domainObjectName="xxx" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> <table tableName="xx" domainObjectName="xxx" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> </context> </generatorConfiguration>差点忘记了,还需要一个db.properties文件,这个应该很常见了
jdbc.driver=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/xxx?characterEncoding=utf-8jdbc.username=rootjdbc.password=
好了,这样就可以了,Maven Run一下就行了
0 0
- Mybatis generator配置方法
- mybatis generator.xml 配置
- Maven,Mybatis-generator配置
- Mybatis generator 配置详解
- Mybatis Generator配置说明
- MyBatis Generator 配置
- Mybatis Generator配置说明
- mybatis-generator配置方法
- MyBatis Generator 配置
- 【Mybatis Generator】【配置详解】
- Mybatis generator配置解析
- Mybatis Generator配置说明
- MyBatis Generator 配置详解
- Mybatis Generator配置详解
- Mybatis-generator配置说明
- mybatis Generator 配置详解
- MyBatis Generator 配置详解
- Mybatis Generator配置详解
- LightOJ 1248 Dice (III)
- NGUI中2DSprite在苹果系统上显示出错的问题解决
- 由于ndk引发的几个bug,以及解决方法
- android 运行项目闪退
- 自顶向下分治实现的归并算法
- MyBatis Generator 配置
- Nginx之页面缓存
- NSURLSession的GET和POST请求的封装
- 糗事百科交互式爬虫
- iBatis简单入门教程
- 阿里面经之解答 by cmershen(2)——static/final,HashMap/Hashtable/ConcurrentHashMap
- Android中对于TabPageIndicator开源框架的使用
- Hbase API 操作
- 经验分享:CSS浮动(float,clear)通俗讲解