mybatis springmvc调用oracle存储过程,返回记录集

参考:

http://bbs.csdn.net/topics/390866155

辅助参考:

http://www.2cto.com/kf/201307/226848.html

http://blog.csdn.net/grhlove123/article/details/7549290

在smm中,这样的controller编写方式是不一样的;

存储过程:

create or replace procedure pro_getchart(chart_cur out sys_refcursor) is

begin

  open chart_cur for
    select * from dic_chart;

end pro_getchart;

MapperXML:

    <select id="getChartByPro" statementType="CALLABLE" parameterType="map" >
     <![CDATA[
         call pro_getchart(
        #{chart_cur,mode=OUT,jdbcType=CURSOR,javaType=java.sql.ResultSet,resultMap=com.stono.dao.server.chart.DicChartMapper.BaseResultMap}
        ) 
    ]]>
    </select>

DAO Interface:

package com.stono.dao.server.chart;

import java.util.List;
import java.util.Map;

import com.stono.model.server.chart.DicChart;

public interface DicChartMapper {
     

    List<DicChart> getChartByPro(Map<String, Object> map);
}

service :

......

@Service("DicChartService")
public class DicChartServiceImpl implements DicChartServiceI {

     
    @Autowired
    DicChartMapper dicChartMapper;

     
    @SuppressWarnings("unchecked")
    @Override
    public List<DicChart> getChartByPro() { 
        Map<String, Object> map = new HashMap<String, Object>();
        dicChartMapper.getChartByPro(map);
        return (List<DicChart>) map.get("chart_cur");
    }

}

Controller:

......

@Controller
@RequestMapping("/DicChart")
public class DicChartController {

    @Autowired
    DicChartServiceI chartServiceI;
 

    @RequestMapping(value = "/getChartByPro")
    @ResponseBody
    List<DicChart> getChartByPro() {
        return chartServiceI.getChartByPro();
    }
}

就是在调用Mapper的时候使用map参数,调用结束之后再用get方法得到对象;

 如果返回的是一个字段,也要用这样的方式,返回的是对象;然后再从对象中获取该属性;