mybatis表连接查询
下面是mybatis表连接查询:
<!--订单表--> <resultMap id="BaseResultList" type="com.qianmo.foru.Cache.OrderInfoAndUser"> <id column="user_id" jdbcType="CHAR" property="userId" /> <id column="order_no" jdbcType="CHAR" property="orderNo" /> <id column="order_type" jdbcType="CHAR" property="orderType" /> <result column="order_stat" jdbcType="VARCHAR" property="orderStat" /> <result column="txn_type" jdbcType="VARCHAR" property="txnType" /> <result column="order_user_id" jdbcType="VARCHAR" property="orderUserId" /> <result column="recive_user_id" jdbcType="VARCHAR" property="reciveUserId" /> <result column="order_user_name" jdbcType="VARCHAR" property="orderUserName" /> <result column="mobl_no" jdbcType="VARCHAR" property="moblNo" /> <result column="demand_title" jdbcType="VARCHAR" property="demandTitle" /> <result column="demand_content" jdbcType="VARCHAR" property="demandContent" /> <result column="demand_pic" jdbcType="VARCHAR" property="demandPic" /> <result column="urgent_push_ident" jdbcType="CHAR" property="urgentPushIdent" /> <result column="order_address" jdbcType="VARCHAR" property="orderAddress" /> <result column="favor_price" jdbcType="VARCHAR" property="favorPrice" /> <result column="goods_budget" jdbcType="VARCHAR" property="goodsBudget" /> <result column="spread_price" jdbcType="VARCHAR" property="spreadPrice" /> <result column="snap_date_time" jdbcType="VARCHAR" property="snapDateTime" /> <result column="order_txn_amt" jdbcType="VARCHAR" property="orderTxnAmt" /> <result column="order_finish_stat" jdbcType="VARCHAR" property="orderFinishStat" /> <result column="order_crt_date_time" jdbcType="CHAR" property="orderCrtDateTime" /> <result column="order_upd_date_time" jdbcType="CHAR" property="orderUpdDateTime" /> <result column="order_comment_finish_date_time" jdbcType="CHAR" property="orderCommentFinishDateTime" /> <result column="auto_trans_date_time" jdbcType="CHAR" property="autoTransDateTime" /> <result column="version" jdbcType="VARCHAR" property="version" /> <result column="remark" jdbcType="VARCHAR" property="remark" /> <result column="profit_amt" jdbcType="VARCHAR" property="profitAmt" /> <result column="user_name" jdbcType="VARCHAR" property="userName" />//用户昵称 <result column="user_face_img" jdbcType="VARCHAR" property="userFaceImg" /> //用户表的用户头像 </resultMap>
业务需求是查询订单,并且查出下单人的头像和昵称,这个时候需要新建一个适合这个resultMap的实体been进行接收,
type="com.qianmo.foru.Cache.OrderInfoAndUser"
<!--查询订单--> <select id="queryOrderByAll" parameterType="com.qianmo.foru.bean.dto.OrderInfo" resultMap="BaseResultList"> select oi.order_no, oi.order_type, oi.order_stat, oi.txn_type, oi.order_user_id, oi.recive_user_id, oi.order_user_name, oi.mobl_no, oi.demand_title, oi.demand_content, oi.demand_pic, oi.urgent_push_ident, oi.order_address, oi.favor_price, oi.goods_budget, oi.spread_price, oi.snap_date_time, oi.order_txn_amt, oi.order_finish_stat, oi.order_crt_date_time, oi.order_upd_date_time, oi.order_comment_finish_date_time, oi.auto_trans_date_time, oi.version, oi.remark, ui.user_name as userName, ui.user_face_img as userFaceImage from order_info oi,user_info ui where oi.order_user_id = ui.user_id <if test="orderNo != null"> AND oi.order_no = #{orderNo,jdbcType=VARCHAR} </if> <if test="orderUserId != null"> AND oi.order_user_id = #{orderUserId,jdbcType=VARCHAR} </if> <if test="reciveUserId != null"> AND oi.recive_user_id = #{reciveUserId,jdbcType=VARCHAR} AND oi.order_finish_stat != '00' </if> <if test="orderFinishStat != null"> AND oi.order_finish_stat = #{orderFinishStat,jdbcType=VARCHAR} </if> <if test="remark != null"> OR oi.order_finish_stat = #{remark,jdbcType=VARCHAR} </if> <if test="orderType != null"> AND oi.order_type = #{orderType,jdbcType=CHAR} </if> AND oi.order_stat = #{orderStat,jdbcType=VARCHAR} AND oi.order_finish_stat!='04' AND oi.txn_type != '01' AND oi.txn_type != '02' ORDER BY oi.order_crt_date_time DESC </select>
1 package com.qianmo.foru.Cache; 2 3 import com.qianmo.foru.bean.dto.OrderInfoKey; 4 5 /** 6 * Created Author: anpei 7 * Created Time 2017/6/13 0013. 8 */ 9 public class OrderInfoAndUser extends OrderInfoKey{ 10 private String orderStat;//订单状态 11 12 private String txnType;//交易类型 13 14 private String orderUserId;//下单人userId 15 16 private String reciveUserId;//接单人userId 17 18 private String orderUserName;//下单人姓名 19 20 private String moblNo;//下单人手机号 21 22 private String demandTitle;//需求标题 23 24 private String demandContent;//需求内容 25 26 private String demandPic;//需求图片 27 28 private String urgentPushIdent;//加急推送标识 29 30 private String orderAddress;//订单地址 31 32 private String favorPrice;//跑腿价格 33 34 private String goodsBudget;//商品预算 35 36 private String spreadPrice;//差价 37 38 private String snapDateTime;//抢单时间 39 40 private String orderTxnAmt;//订单交易金额 41 42 private String orderFinishStat;//订单完成状态 43 44 private String orderCrtDateTime;//订单生成时间 45 46 private String orderUpdDateTime;//订单更新时间 47 48 private String orderCommentFinishDateTime;//订单好评转账时间 49 50 private String autoTransDateTime;//自动好评转账时间 51 52 private String version;//版本 53 54 private String remark;//备注 55 56 private String profitAmt;//获利金额 57 58 private String userName;//用户名称 59 private String userFaceImage;//下单人用户头像 60 //响应的临时字段 61 private String yyyyMMdd;//日期 62 private String hhmm;//时间 63 private String[] imgStr;//多张图片数组 64 private String showOrderType;//移动端显示的订单类型 00:求助订单 01:服务订单 02:需求详情 65 66 public String getUserName() { 67 return userName; 68 } 69 70 public void setUserName(String userName) { 71 this.userName = userName.trim(); 72 } 73 74 public String getShowOrderType() { 75 return showOrderType; 76 } 77 78 public void setShowOrderType(String showOrderType) { 79 this.showOrderType = showOrderType.trim(); 80 } 81 82 public String getProfitAmt() { 83 return profitAmt; 84 } 85 86 public void setProfitAmt(String profitAmt) { 87 this.profitAmt = profitAmt; 88 } 89 90 public String[] getImgStr() { 91 return imgStr; 92 } 93 94 public void setImgStr(String[] imgStr) { 95 this.imgStr = imgStr; 96 } 97 98 public String getYyyyMMdd() { 99 return yyyyMMdd; 100 } 101 102 public void setYyyyMMdd(String yyyyMMdd) { 103 this.yyyyMMdd = yyyyMMdd; 104 } 105 106 public String getHhmm() { 107 return hhmm; 108 } 109 110 public void setHhmm(String hhmm) { 111 this.hhmm = hhmm; 112 } 113 114 public String getUserFaceImage() { 115 return userFaceImage; 116 } 117 118 public void setUserFaceImage(String userFaceImage) { 119 this.userFaceImage = userFaceImage; 120 } 121 122 public String getOrderStat() { 123 return orderStat; 124 } 125 126 public void setOrderStat(String orderStat) { 127 this.orderStat = orderStat == null ? null : orderStat.trim(); 128 } 129 130 public String getTxnType() { 131 return txnType; 132 } 133 134 public void setTxnType(String txnType) { 135 this.txnType = txnType == null ? null : txnType.trim(); 136 } 137 138 public String getOrderUserId() { 139 return orderUserId; 140 } 141 142 public void setOrderUserId(String orderUserId) { 143 this.orderUserId = orderUserId == null ? null : orderUserId.trim(); 144 } 145 146 public String getReciveUserId() { 147 return reciveUserId; 148 } 149 150 public void setReciveUserId(String reciveUserId) { 151 this.reciveUserId = reciveUserId == null ? null : reciveUserId.trim(); 152 } 153 154 public String getOrderUserName() { 155 return orderUserName; 156 } 157 158 public void setOrderUserName(String orderUserName) { 159 this.orderUserName = orderUserName == null ? null : orderUserName.trim(); 160 } 161 162 public String getMoblNo() { 163 return moblNo; 164 } 165 166 public void setMoblNo(String moblNo) { 167 this.moblNo = moblNo == null ? null : moblNo.trim(); 168 } 169 170 public String getDemandTitle() { 171 return demandTitle; 172 } 173 174 public void setDemandTitle(String demandTitle) { 175 this.demandTitle = demandTitle == null ? null : demandTitle.trim(); 176 } 177 178 public String getDemandContent() { 179 return demandContent; 180 } 181 182 public void setDemandContent(String demandContent) { 183 this.demandContent = demandContent == null ? null : demandContent.trim(); 184 } 185 186 public String getDemandPic() { 187 return demandPic; 188 } 189 190 public void setDemandPic(String demandPic) { 191 this.demandPic = demandPic; 192 } 193 194 public String getUrgentPushIdent() { 195 return urgentPushIdent; 196 } 197 198 public void setUrgentPushIdent(String urgentPushIdent) { 199 this.urgentPushIdent = urgentPushIdent == null ? null : urgentPushIdent.trim(); 200 } 201 202 public String getOrderAddress() { 203 return orderAddress; 204 } 205 206 public void setOrderAddress(String orderAddress) { 207 this.orderAddress = orderAddress == null ? null : orderAddress.trim(); 208 } 209 210 public String getFavorPrice() { 211 return favorPrice; 212 } 213 214 public void setFavorPrice(String favorPrice) { 215 this.favorPrice = favorPrice == null ? null : favorPrice.trim(); 216 } 217 218 public String getGoodsBudget() { 219 return goodsBudget; 220 } 221 222 public void setGoodsBudget(String goodsBudget) { 223 this.goodsBudget = goodsBudget == null ? null : goodsBudget.trim(); 224 } 225 226 public String getSpreadPrice() { 227 return spreadPrice; 228 } 229 230 public void setSpreadPrice(String spreadPrice) { 231 this.spreadPrice = spreadPrice == null ? null : spreadPrice.trim(); 232 } 233 234 public String getSnapDateTime() { 235 return snapDateTime; 236 } 237 238 public void setSnapDateTime(String snapDateTime) { 239 this.snapDateTime = snapDateTime == null ? null : snapDateTime.trim(); 240 } 241 242 public String getOrderTxnAmt() { 243 return orderTxnAmt; 244 } 245 246 public void setOrderTxnAmt(String orderTxnAmt) { 247 this.orderTxnAmt = orderTxnAmt == null ? null : orderTxnAmt.trim(); 248 } 249 250 public String getOrderFinishStat() { 251 return orderFinishStat; 252 } 253 254 public void setOrderFinishStat(String orderFinishStat) { 255 this.orderFinishStat = orderFinishStat == null ? null : orderFinishStat.trim(); 256 } 257 258 public String getOrderCrtDateTime() { 259 return orderCrtDateTime; 260 } 261 262 public void setOrderCrtDateTime(String orderCrtDateTime) { 263 this.orderCrtDateTime = orderCrtDateTime == null ? null : orderCrtDateTime.trim(); 264 } 265 266 public String getOrderUpdDateTime() { 267 return orderUpdDateTime; 268 } 269 270 public void setOrderUpdDateTime(String orderUpdDateTime) { 271 this.orderUpdDateTime = orderUpdDateTime == null ? null : orderUpdDateTime.trim(); 272 } 273 274 public String getOrderCommentFinishDateTime() { 275 return orderCommentFinishDateTime; 276 } 277 278 public void setOrderCommentFinishDateTime(String orderCommentFinishDateTime) { 279 this.orderCommentFinishDateTime = orderCommentFinishDateTime == null ? null : orderCommentFinishDateTime.trim(); 280 } 281 282 public String getAutoTransDateTime() { 283 return autoTransDateTime; 284 } 285 286 public void setAutoTransDateTime(String autoTransDateTime) { 287 this.autoTransDateTime = autoTransDateTime == null ? null : autoTransDateTime.trim(); 288 } 289 290 public String getVersion() { 291 return version; 292 } 293 294 public void setVersion(String version) { 295 this.version = version == null ? null : version.trim(); 296 } 297 298 public String getRemark() { 299 return remark; 300 } 301 302 public void setRemark(String remark) { 303 this.remark = remark == null ? null : remark.trim(); 304 } 305 }
大概就是这样子了。
mapper代码:
//按各种条件查询订单 List<OrderInfoAndUser> queryOrderByAll(OrderInfo orderInfo);