- 首先建立相关的存储过程,如图:
2.在service实现层填充参数 例如:
@Override
public Dto addFloorList(BannerRequest req)
{
Dto dto = new Dto();
List list = new ArrayList();
for (int i = 0; i < 3; i++)
{
IndexFloor flr = new IndexFloor();
flr.setFloorId(i + 3);
flr.setFloorTitle("测试数据 " + i + 1);
flr.setFlrSort(i + 1);
flr.setFlrCat(2);
list.add(flr);
}
Map param = new HashMap();
param.put("id", 2);
param.put("floor_list", list);
//调用存储过程
webMapper.spInsertInfo(param);
int rtnCode = (Integer) param.get("rtnCode");
String rtnMsg = String.valueOf(param.get("rtnMsg"));
System.out.print(rtnCode + "------" + rtnMsg);
3.编写工具类,用来处理Array参数:
核心代码如下(详见附件中的 handler/ArrayHandler.java):
(注意:上图中的IndexFloor为测试bean。具体bean对象,根据需要编写)
4.在MyBatis配置文件中,配置
配置代码如下:
5.在Mapper.xml文件中调用存储过程并传参数:
6.调试代码。
参考资料:
1.how-to-pass-java-list-of-objects-to-oracle-stored-procedure-using-mybatis:
http://stackoverflow.com/questions/12719689/how-to-pass-java-list-of-objects-to-oracle-stored-procedure-using-mybatis
2. myBatis自定义传入参数类型(TypeHandler)
http://jusesgod.iteye.com/blog/1740889