ibatis中mapper.xml编写


1、入参

package com.ldygo.order.dao.mybatis.dto.custom;
import java.io.Serializable;
import java.util.List;

import cn.openlo.gear.dataobject.PersistentDTOSupport;

/**
 * 

Title: OrderReportQuery

*

Description: 订单报表导出查询输入参数

*

Copyright: openlo.cn Copyright (C) 2017

* * @author huangl * @since 2017年5月23日 上午10:49:10 */ public class OrderReportQuery extends PersistentDTOSupport implements Serializable { private static final long serialVersionUID = 1L; private String orderNo; private List orderStatus; private String umName; private int caroutMethod; private int delayHour; public String getOrderNo() { return orderNo; } public void setOrderNo(String orderNo) { this.orderNo = orderNo; } public List getOrderStatus() { return orderStatus; } public void setOrderStatus(List orderStatus) { this.orderStatus = orderStatus; } public String getUmName() { return umName; } public void setUmName(String umName) { this.umName = umName; } public int getCaroutMethod() { return caroutMethod; } public void setCaroutMethod(int caroutMethod) { this.caroutMethod = caroutMethod; } public int getDelayHour() { return delayHour; } public void setDelayHour(int delayHour) { this.delayHour = delayHour; } }


2、返回结果

package com.ldygo.order.dao.mybatis.dto.custom;
import java.io.Serializable;
import java.util.List;

import cn.openlo.gear.dataobject.PersistentDTOSupport;

/**
 * 

Title: OrderReportQueryResults

*

Description: 订单报表导出结果

*

Copyright: openlo.cn Copyright (C) 2017

* * @author huangl * @since 2017年5月23日 上午10:49:10 */ public class OrderReportQueryResults extends PersistentDTOSupport implements Serializable { private static final long serialVersionUID = 1L; private String orderNo; private String orderStatus; private String umName; private int caroutMethod; private int delayHour; public String getOrderNo() { return orderNo; } public void setOrderNo(String orderNo) { this.orderNo = orderNo; } public String getOrderStatus() { return orderStatus; } public void setOrderStatus(String orderStatus) { this.orderStatus = orderStatus; } public String getUmName() { return umName; } public void setUmName(String umName) { this.umName = umName; } public int getCaroutMethod() { return caroutMethod; } public void setCaroutMethod(int caroutMethod) { this.caroutMethod = caroutMethod; } public int getDelayHour() { return delayHour; } public void setDelayHour(int delayHour) { this.delayHour = delayHour; } }

3、查询mapper接口

package com.ldygo.order.dao.mybatis.client.custom;

import java.util.List;

import org.apache.ibatis.annotations.Param;

import com.ldygo.order.dao.mybatis.dto.OrderMaster;
import com.ldygo.order.dao.mybatis.dto.custom.OrderReportQuery;
import com.ldygo.order.dao.mybatis.dto.custom.OrderReportQueryResults;

import cn.openlo.dataobject.DAO;

/**
 * 

Title: OrderOutportReportMapper

*

Description: 查询报表导出接口方法

*

Copyright: openlo.cn Copyright (C) 2017

* * @author huangl * @since 2017年5月23日 上午10:45:33 */ public interface OrderReportQueryMapper extends DAO { List queryOrderReport(OrderReportQuery params); }

4、【OrderReportQueryMapper.xml】




	
	
    	
    	
    	
    	
    	
 	
 
 
  
  
  


4.1

4.2

#{orderNo,jdbcType.INTEGER}

org.apache.ibatis.type.JdbcType.INTEGER

4.3

${orderNo}


5、测试

package com.ldygo.order.controller.test;

import java.util.List;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.ldygo.order.dao.mybatis.client.custom.OrderReportQueryMapper;
import com.ldygo.order.dao.mybatis.dto.custom.OrderReportQuery;
import com.ldygo.order.dao.mybatis.dto.custom.OrderReportQueryResults;

import cn.openlo.gear.test.GearContextConfiguration;
import cn.openlo.gear.test.GearTestBase;

@GearContextConfiguration(boxName = "box01", boxHome = "${user.dir}/src/test/resources/box01/", gearName = "zuche-order-online", gearStartTimeout = 2000000)
public class OrderTaskTest extends GearTestBase {
	
	@Autowired
	private OrderReportQueryMapper orderOutportReportMapper;
	
    @Test
    public void getActRentDays() throws Exception {
    	
    	OrderReportQuery params = new OrderReportQuery();
    	params.setOrderNo("20161225000047");
    	List orderStatus = Lists.newArrayList();
    	orderStatus.add("S03");
    	orderStatus.add("s06");
		params.setOrderStatus(orderStatus);
		
		params.setCaroutMethod(1);
		params.setDelayHour(0);
		
		List bb = this.orderOutportReportMapper.queryOrderReport(params);
    	System.out.println("<<<<<<<<<<<<<<<<<<<");
    	System.out.println(JSON.toJSONString(bb));
    
    	
    }

}

6、注意#{}、${}的差别

      select * from order_master  where order_no = ?

     11212121(String)

      select * from order_mastet where order_no = '11212121'

7、执行sql语句

==>  Preparing: select * from order_master WHERE ORDER_STATUS in ( ? , ? ) and order_no = ? and CAROUT_DELIVER_METHOD = ? and DELAY_HOUR = 0 
==> Parameters: S03(String), s06(String), 20161225000047(String), 1(Integer)
<==      Total: 1






你可能感兴趣的:(Mybatis/ibatis)