mybatis中自定义1对1的resultMap
2015-07-01 17:22
246 查看
1·首先是javabean:
2·编写resultMap
3·调用:
public class jeweryCartTbl { private String id; private String memberid; private String jeweryAllId; private String type; private Integer count; private String ischeck; private Date createTime; private Date lastmodifyTime; private String categoryid; private JeweryTbl jeweryTbl; <span style="color:#FF0000;"><strong>//这个是1对1的属性值</strong></span> public jeweryTbl getjeweryTbl() { return jeweryTbl; } public void setjeweryTbl(jeweryTbl jeweryTbl) { this.jeweryTbl = jeweryTbl; } public String getId() { return id; } public void setId(String id) { this.id = id == null ? null : id.trim(); } public String getMemberid() { return memberid; } public void setMemberid(String memberid) { this.memberid = memberid == null ? null : memberid.trim(); } public String getjeweryAllId() { return jeweryAllId; } public void setjeweryAllId(String jeweryAllId) { this.jeweryAllId = jeweryAllId == null ? null : jeweryAllId.trim(); } public String getType() { return type; } public void setType(String type) { this.type = type == null ? null : type.trim(); } public Integer getCount() { return count; } public void setCount(Integer count) { this.count = count; } public String getIscheck() { return ischeck; } public void setIscheck(String ischeck) { this.ischeck = ischeck == null ? null : ischeck.trim(); } public Date getCreateTime() { return createTime; } public void setCreateTime(Date createTime) { this.createTime = createTime; } public Date getLastmodifyTime() { return lastmodifyTime; } public void setLastmodifyTime(Date lastmodifyTime) { this.lastmodifyTime = lastmodifyTime; } public String getCategoryid() { return categoryid; } public void setCategoryid(String categoryid) { this.categoryid = categoryid == null ? null : categoryid.trim(); } }
2·编写resultMap
<span style="color:#FF0000;"><strong>//编写对应的resultMap //1·首先property与javabean中的属性一致 //2·如果两个关联的有相同的属性 例如:id 设置成不同的属性</strong></span> <resultMap id="BaseResultMap_1" type="com.model.jeweryCartTbl" > <id column="id" property="id" jdbcType="VARCHAR" /> <result column="memberid" property="memberid" jdbcType="VARCHAR" /> <result column="jewery_all_id" property="jeweryAllId" jdbcType="VARCHAR" /> <result column="type" property="type" jdbcType="VARCHAR" /> <result column="count" property="count" jdbcType="INTEGER" /> <result column="ischeck" property="ischeck" jdbcType="VARCHAR" /> <result column="create_time" property="createTime" jdbcType="TIMESTAMP" /> <result column="lastmodify_time" property="lastmodifyTime" jdbcType="TIMESTAMP" /> <result column="categoryid" property="categoryid" jdbcType="VARCHAR" /> <association property="jeweryTbl" javaType="com.model.jeweryTbl"> <id <span style="color:#FF0000;"><strong>column="jeweryid"</strong></span> property="id" jdbcType="VARCHAR" /> <result column="name" property="name" jdbcType="VARCHAR" /> <result column="price" property="price" jdbcType="DECIMAL" /> </association> </resultMap>
3·调用:
//相同的属性定义重命名 //如果不设置不同名字。相同的属性值会显示一个值(会覆盖) <select id="findCheckedCartByMember" resultMap="BaseResultMap_1"> select dct.*,dt.price,<span style="color:#FF0000;"><strong>dt.id as jeweryid</strong></span> from jewery_cart_tbl dct left join jewery_category_value_tbl dcvt on dct.jewery_all_id = dcvt.id left join jewery_tbl dt on dcvt.jewery_all_id = dt.id where dct.ischeck = '1' and dt.is_sale = '1' <if test="memberid != null"> and dct.memberid = #{memberid,jdbcType=VARCHAR} </if> </select>
相关文章推荐
- js中Array数组的操作
- 慎用ArrayList的contains方法,使用HashSet的contains方法代替
- SMP学习笔记之使用REST API在任何操作系统上消费SMP的OData服务
- Rectangle Area
- iOS 如何在一个app中调用另一个app
- solr 启动报错Cannot load analyzer: org.wltea.analyzer.lucene.IKAnalyzer
- 转-Activity中使用orientation属性讲解及需注意的问题
- 详解Eclipse断点
- 在子类中调用父类的带参数的构造方法
- 织梦常用标签
- JSTL中if...else...逻辑判断的简单用法
- 甲骨文战略主导下 MySQL 数据库将走向何方
- Makefile中命令前的@和-符号
- Java中hashCode的作用
- Fact Dimension
- Linux下p2p的聊天功能实现
- Java反射
- php webservice实例
- php面向对象编程之--封装
- socket的半包,粘包与分包的问题