



下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、MyBatis Generator使用1、相关文件关于Mybatis-Generator的下载由于我使用的是Mysql数据库,这里需要在准备一个连接mysql数据库的驱动jar包以下是相关文件截图: 和Hibernate逆向生成一样,这里也需要一个配置文件:generatorConfig.xml1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE generatorConfiguration 3 PUBLIC "-//DTD MyBatis G
2、enerator Configuration 1.0/EN" 4 "://dtd/mybatis-generator-config_1_0.dtd"> 5 <generatorConfiguration> 6 <!-数据库驱动-> 7 <classPathEntry location="mysql-connector-java-5.0.8-bin.jar"/> 8 <context id="DB2Tables" targetRuntime="My
3、Batis3"> 9 <commentGenerator>10 <property name="suppressDate" value="true"/>11 <property name="suppressAllComments" value="true"/>12 </commentGenerator>13 <!-数据库链接地址账号密码->14 <jdbcConnection driverClass="" conn
4、ectionURL="jdbc:mysql:/localhost/mymessages" userId="root" password="root">15 </jdbcConnection>16 <javaTypeResolver>17 <property name="forceBigDecimals" value="false"/>18 </javaTypeResolver>19 <!-生成Model类存放位置->20 <
5、javaModelGenerator targetPackage="lcw.model" targetProject="src">21 <property name="enableSubPackages" value="true"/>22 <property name="trimStrings" value="true"/>23 </javaModelGenerator>24 <!-生成映射文件存放位置->25 <s
6、qlMapGenerator targetPackage="lcw.mapping" targetProject="src">26 <property name="enableSubPackages" value="true"/>27 </sqlMapGenerator>28 <!-生成Dao类存放位置->29 <javaClientGenerator type="XMLMAPPER" targetPackage="lcw.dao&quo
7、t; targetProject="src">30 <property name="enableSubPackages" value="true"/>31 </javaClientGenerator>32 <!-生成对应表及类名->33 <table tableName="message" domainObjectName="Messgae" enableCountByExample="false" enableUpdateBy
8、Example="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>34 </context>35 </generatorConfiguration>需要修改文件配置的地方我都已经把注释标注出来了,这里的相关路径(如数据库驱动包,生成对应的相关文件位置可以自定义)不能带有中文。上面配置文件中的:<table
9、tableName="message" domainObjectName="Messgae" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>tableName和domain
10、ObjectName为必选项,分别代表数据库表名和生成的实力类名,其余的可以自定义去选择(一般情况下均为false)。 生成语句文件:java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite 2、使用方法在该目录按住Shift键,右键鼠标选择"在此处打开命令窗口",复制粘贴生成语句的文件代码即可。 看下效果图: 生成相关代码:Message.java1 package lcw.model; 2 3
11、public class Messgae 4 private Integer id; 5 6 private String title; 7 8 private String describe; 9 10 private String content;11 12 public Integer getId() 13 return id;14 15 16 public void setId(Integer id) 17 this.id = id;18 19 20 public String getTitle() 21 return title;22 23 24 public void setTit
12、le(String title) 25 this.title = title = null ? null : title.trim();26 27 28 public String getDescribe() 29 return describe;30 31 32 public void setDescribe(String describe) 33 this.describe = describe = null ? null : describe.trim();34 35 36 public String getContent() 37 return content;38 39 40 pub
13、lic void setContent(String content) 41 this.content = content = null ? null : content.trim();42 43 MessgaeMapper.xml1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE mapper PUBLIC "-//DTD Mapper 3.0/EN" "://dtd/mybatis-3-mapper.dt
14、d" > 3 <mapper namespace="" > 4 <resultMap id="BaseResultMap" type="" > 5 <id column="id" property="id" jdbcType="INTEGER" /> 6 <result column="title" property="title" jdbcType="VARCHAR&
15、quot; /> 7 <result column="describe" property="describe" jdbcType="VARCHAR" /> 8 <result column="content" property="content" jdbcType="VARCHAR" /> 9 </resultMap>10 <sql id="Base_Column_List" >11 id, titl
16、e, describe, content12 </sql>13 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="" >14 select 15 <include refid="Base_Column_List" />16 from message17 where id = #id,jdbcType=INTEGER18 </select>19 <delete id=&
17、quot;deleteByPrimaryKey" parameterType="" >20 delete from message21 where id = #id,jdbcType=INTEGER22 </delete>23 <insert id="insert" parameterType="" >24 insert into message (id, title, describe, 25 content)26 values (#id,jdbcType=INTEGER, #title,jd
18、bcType=VARCHAR, #describe,jdbcType=VARCHAR, 27 #content,jdbcType=VARCHAR)28 </insert>29 <insert id="insertSelective" parameterType="" >30 insert into message31 <trim prefix="(" suffix=")" suffixOverrides="," >32 <if test="id
19、 != null" >33 id,34 </if>35 <if test="title != null" >36 title,37 </if>38 <if test="describe != null" >39 describe,40 </if>41 <if test="content != null" >42 content,43 </if>44 </trim>45 <trim prefix="values
20、 (" suffix=")" suffixOverrides="," >46 <if test="id != null" >47 #id,jdbcType=INTEGER,48 </if>49 <if test="title != null" >50 #title,jdbcType=VARCHAR,51 </if>52 <if test="describe != null" >53 #describe,jdbcType=
21、VARCHAR,54 </if>55 <if test="content != null" >56 #content,jdbcType=VARCHAR,57 </if>58 </trim>59 </insert>60 <update id="updateByPrimaryKeySelective" parameterType="" >61 update message62 <set >63 <if test="title != null" >64 title = #title,jdbcType=VARCHAR,65 </if>66 <if test="describe != null" >67 describe = #describe,jdbcType=VARCHAR,68 </if>69 <if test="content != null" >70 content = #content,
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 电机制造中的高温耐受性设计考核试卷
- 畜牧业养殖技术考核试卷
- 超级食物与养生保健考核试卷
- 纺织原料供应链优化考核试卷
- 葡萄酒酿造废弃物处理与资源化利用考核试卷
- 种子批发物流成本控制与优化考核试卷
- 粮食仓储企业绿色经济企业绿色经济国际标准接轨考核试卷
- 谷物磨制对食品加工业的影响考核试卷
- 医疗机构投资合伙人合作协议范本
- 博物馆学术讲座兼职讲解员聘任协议
- 空调维护保养“三措两案”及空调维修保养方案
- 消防检测流程图
- 挂靠公司司机管理制度
- 《大学生职业发展与生涯规划(高职版)》 教案 第3课 探索自己的职业兴趣
- 化工总经理岗位职责
- 小学英语复习讲座88课件
- 医院发生意外自杀的应急预案流程
- 经济学论文的选题与写作
- 过热蒸汽压力控制设计
- 国际志愿服务培训与实践-浙江外国语学院中国大学mooc课后章节答案期末考试题库2023年
- 其他常见疾病的康复
评论
0/150
提交评论