记录一哈-mybatis使用generator生成代码
2015-09-10 18:00
489 查看
这个是一个maven项目,当然要引用配置文件
pom.xml添加
使用这个插件需要添加一个配置文件generatorConfig.xml,
这个是重点
网上搜了一些,改改就是自己的了
我的jdbc.properties
基本工作就好了,因为是maven的,启动命令是这个样子的
运行后就是这个样子
然后没了,然后需要更多的网上搜搜,我也是那样的啊
,不知道搜的那几篇教程,如有侵权,请联系我
pom.xml添加
<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>
使用这个插件需要添加一个配置文件generatorConfig.xml,
这个是重点
<?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> <!--jdbc配置文件--> <properties resource="jdbc.properties"/> <!--jdbc的路径--> <classPathEntry location="C:/Users/fei/.m2/repository/mysql/mysql-connector-java/5.1.22/mysql-connector-java-5.1.22.jar"/> <context id="default" targetRuntime="MyBatis3"> <commentGenerator> <!-- 不生成注解 --> <property name="suppressAllComments" value="true"/> <!--除去注释--> <property name="suppressDate" value="true"/> </commentGenerator> <!--不解释--> <jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}"> </jdbcConnection> <javaTypeResolver> <!-- 对于数据库中DECIMAL or NUMERIC类型字段是否强制使用java.math.BigDecimal表示 ,搜的--> <property name="forceBigDecimals" value="false"/> </javaTypeResolver> <!-- Model模型生成器 targetPackage 指定生成的model生成所在的包名 targetProject 指定在该项目下所在的路径 --> <javaModelGenerator targetPackage="com.fei.model" targetProject="src/main/java"> <!-- 是否对model添加 构造函数 --> <property name="constructorBased" value="true"/> <!-- 是否允许子包,即targetPackage.schemaName.tableName --> <property name="enableSubPackages" value="false"/> <!-- 建立的Model对象是否 不可改变 即生成的Model对象不会有 setter方法,只有构造方法 --> <property name="immutable" value="false"/> <!-- 是否对类CHAR类型的列的数据进行trim操作 --> <property name="trimStrings" value="true"/> </javaModelGenerator> <!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 --> <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources"> <property name="enableSubPackages" value="false"/> </sqlMapGenerator> <!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码 type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象 type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象 type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 --> <javaClientGenerator targetPackage="com.fei.dao" targetProject="src/main/java" type="MIXEDMAPPER"> <property name="enableSubPackages" value=""/> <!-- 定义Maper.java 源代码中的ByExample() 方法的可视性,可选的值有: public; private; protected; default 注意:如果 targetRuntime="MyBatis3",此参数被忽略 --> <property name="exampleMethodVisibility" value=""/> <!-- 方法名计数器 Important note: this property is ignored if the target runtime is MyBatis3. --> <property name="methodNameCalculator" value=""/> <!-- 为生成的接口添加父接口 --> <property name="rootInterface" value=""/> </javaClientGenerator> <table tableName="user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> </context> </generatorConfiguration>
网上搜了一些,改改就是自己的了
我的jdbc.properties
driver=com.mysql.jdbc.Driver url=jdbc:mysql:///test username=root password=root #定义初始连接数 initialSize=0 #定义最大连接数 maxActive=20 #定义最大空闲 maxIdle=20 #定义最小空闲 minIdle=1 #定义最长等待时间 maxWait=60000
基本工作就好了,因为是maven的,启动命令是这个样子的
mybatis-generator:generate -e
运行后就是这个样子
然后没了,然后需要更多的网上搜搜,我也是那样的啊
,不知道搜的那几篇教程,如有侵权,请联系我
相关文章推荐
- Eclipse将引用了第三方jar包的Java项目打包成jar文件的两种方法
- 关于烂代码的那些事(中)
- RTP协议全解(H264码流和PS流)
- java验证一个数是2的次幂
- 2015.09.09 C++笔记
- C++例子:setprecision
- 用Google的gflags轻松的编码解析命令行参数
- 关于烂代码的那些事(上)
- C++异常机制
- Java CheckException与UncheckException
- thinkphp url大小写更改
- spring容器创建对象的生命周期
- 【Spring】Spring MVC 的json问题(406 Not Acceptable)
- C#使用GET、POST请求获取结果
- Algorithms—15.3Sum
- Maven Struts2
- struts2的获取请求方法
- Java访问权限修饰词
- java中thread的start()和run()的区别
- QT 不能在指定目录生成目标文件