mybatis中自定义1对1的resultMap
来源:互联网 发布:水泥自流平环保吗 知乎 编辑:程序博客网 时间:2024/06/17 20:21
1·首先是javabean:
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.idleft join jewery_tbl dton 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>
0 0
- mybatis中自定义1对1的resultMap
- MYBATIS中resultMap和parameterMap的使用
- mybatis中resultMap和resultType的区别
- MYBATIS中resultMap和parameterMap的使用
- MyBatis中resultMap和resultType的使用
- MyBatis中ResultMap和ResultType的区别
- MyBatis中resultType和resultMap的区别
- mybatis中resulttype和resultmap的区别
- MyBatis中resultType和resultMap的区别
- MyBatis中resultMap和parameterMap的使用
- mybatis中resultMap的几种用法
- Mybatis中resultMap
- Mybatis中resultMap
- Mybatis中resultMap
- Mybatis中resultMap
- Mybatis中resultMap
- Mybatis中resultMap
- Mybatis中resultMap
- Java基础:泛型及其擦除性、不可协变性
- Algorithms—171.Excel Sheet Column Number
- Rectangle Area
- iOS 如何在一个app中调用另一个app
- 慎用ArrayList的contains方法,使用HashSet的contains方法代替
- mybatis中自定义1对1的resultMap
- 自学笔记-C语言复习2015年7月1日
- UIImagePickerController 状态栏颜色改变,自定义返回按钮
- SMP学习笔记之使用REST API在任何操作系统上消费SMP的OData服务
- Linux给指定用户或全部用户(已登录)发送消息
- Xcode7.0beta真机调试出现"Could not find Developer Disk Image"提示
- Tmux快捷键
- 给自己的类实现下标访问
- 无密码访问ssh