1. 程式人生 > >EasyUI條件查詢 mybatis接收Map 查詢

EasyUI條件查詢 mybatis接收Map 查詢

前端頁面

 <div class="search_style">     
      <ul class="search_content ">
       <li style="margin-right:20px;float: left;line-height: 30px"><label class="l_f">訂單編號</label><input id="oid" class="easyui-textbox" data-options="prompt:'訂單編號',validType:'unnormal'" style="width:200px"></input></li>
       <li style="margin-right:20px;float: left;line-height: 30px"><label class="l_f">時間</label><input id="otime" class="easyui-datebox"; editable="fasle"; style=" margin-left:10px;"></li>
       <li style="margin-right:20px;float: left;line-height: 30px"><label class="l_f">訂單狀態</label><select id="ostatus" id="cc" class="easyui-combobox" name="status" style="width:200px;">
		    <option value="0">全部</option>
		    <option value="1">待付款</option>
		    <option value="2">待發貨</option>
		    <option value="3">待收貨</option>
		    <option value="4">交易成功</option>
		    <option value="5">待評價</option>
		    <option value="6">交易關閉</option>
		</select>
		</li>
       <li style="margin-right:20px;float: left;line-height: 30px;width:90px;"><button type="button" class="btn_search"><i class="search"></i>查詢</button></li>
      </ul>
 </div>

js程式碼


$(function(){
	 $("button").click(function(){ 
		    var oid=$("#oid").val();//取訂單號
		    var otime=$("#otime").datebox('getValue');//取訂單時間
		    var ostatus=$("#ostatus").combobox('getValue');//取訂單狀態
		    var map={"oid" : oid,"otime":otime,"ostatus":ostatus};
		    var str=JSON.stringify(map);
		    $("#goodsorderList").datagrid({
		    	type : "GET",
				url : 'order/search/list',
				queryParams : {
					"oid" : oid,
					"otime":otime,
					"ostatus":ostatus
				},
				datatype : 'json',
				onLoadSuccess : function(data) {
					var result = eval(data).total;
					if (result == 0) {
						$.messager.alert('提示', '訂單不存在!');
					}
				}
			});				
			})		
})

Controller層程式碼

//搜尋查詢訂單列表
	@RequestMapping(value="/search/list",method=RequestMethod.GET)
	@ResponseBody
	public EasyUIDataGridResult getSearchOrderList(String oid,String otime,String ostatus,Integer page,Integer rows) {
		Map<String, Object> map=new HashMap<>();
		if(!oid.equals("")) {
			map.put("orderId",oid);			
		}else {
			map.put("orderId",null);}
		if(!otime.equals("")) {
			map.put("createdtime", otime);			
		}else {
			map.put("createdtime", null);
		}if(!ostatus.equals("0")) {
			map.put("status",ostatus);			
		}else {
			map.put("status",null);	
		}
		EasyUIDataGridResult result = orderService.querygoodsOrderList(map, page, rows);
		return result;
		
	}

Service層程式碼

public EasyUIDataGridResult querygoodsOrderList(Map<String, Object> map, int page, int rows) {
		PageHelper.startPage(page, rows);
		List<OrderPojo> list = orderMapper.queryGoodsOrderList(map, page, rows);
		List<OrderListPoJo> listpojo=new ArrayList<>();
		for(OrderPojo pojo:list) {
			OrderListPoJo pojolist=new OrderListPoJo();				
			pojolist.setOrder_id(pojo.getOrder_id());
			pojolist.setPayment(pojo.getPayment());
			pojolist.setPayment_type(pojo.getPayment_type());
			pojolist.setPost_fee(pojo.getPost_fee());
			pojolist.setDeedvalue(pojo.getDeedvalue());
			pojolist.setStatus(pojo.getStatus());
			pojolist.setCreate_time(pojo.getCreate_time());
			pojolist.setPayment_time(pojo.getPayment_time());
			pojolist.setConsign_time(pojo.getConsign_time());
			pojolist.setClose_time(pojo.getClose_time());
			pojolist.setEnd_time(pojo.getClose_time());
			pojolist.setShipping_code(pojo.getShipping_code());
			pojolist.setShipping_name(pojo.getShipping_name());
			pojolist.setShop_id(pojo.getShop_id());
			pojolist.setShop_name(pojo.getShop_name());
			pojolist.setSellerphone(getSellerPhone(pojo.getShop_id()));			
			listpojo.add(pojolist);
		}
		EasyUIDataGridResult result=new EasyUIDataGridResult();
		result.setRows(listpojo);
		PageInfo<OrderPojo> info=new PageInfo<>(list);
		result.setTotal(info.getTotal());
		return result;
	}

Dao層程式碼

List<OrderPojo> queryGoodsOrderList(@Param(value="map")Map<String, Object> map,int page,int rows);

mapper.xml

<select id="queryGoodsOrderList" parameterType="map" resultType="com.test.pojo.OrderPojo">
  	SELECT
	t1.order_id,
	t1.payment,
	t1.payment_type,
	t1.post_fee,
	t1.deed_value 'deedvalue',
	t1.`status`,
	t1.create_time,
	t1.payment_time,
	t1.consign_time,
	t1.end_time,
	t1.close_time,
	t1.shipping_code,
	t1.shipping_name,
	t2.shop_id,
	t2.shop_name
	FROM tb_order t1  LEFT JOIN 
   tb_seller_order t2 ON t1.order_id=t2.order_id
 <where>
	  <if test="map.orderId!=null and map.orderId!=''">
	  	 and t1.order_id like "%"#{map.orderId}"%"
	  </if>
	   <if test="map.createdtime!=null and map.createdtime!=''">
	     and date_format(t1.create_time,'%Y-%m-%d')=#{map.createdtime}
	  </if>
	  <if test="map.status!=null and map.status!=''">
	     and t1.status=#{map.status}
	  </if>
  </where>
 	ORDER BY t1.create_time DESC
  </select>

好久沒寫mapper順便做個記錄,以上就是所有的程式碼,有問題的地方請大神指正。