Java中调用存储过程

dao层:

import java.util.Map;
public interface AppGthdDao {
    public String gthd(Map map);
}

mapper层

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.socialsecurity.dao.AppGthdDao">
    <select id="gthd" statementType="CALLABLE">
        {
        call SHBXSB.APP_GTHD (
        #{IS_AAE100,mode=IN,jdbcType=VARCHAR},
        #{IS_AAZ001,mode=IN,jdbcType=DOUBLE},
        #{IS_AAC002,mode=IN,jdbcType=VARCHAR},
        #{IS_AAE030,mode=IN,jdbcType=DATE},
        #{IS_AAE031,mode=IN,jdbcType=DATE},
        #{IS_AAC040,mode=IN,jdbcType=DOUBLE},
        #{Os_ErrInfo,mode=OUT,jdbcType=VARCHAR})
        }
    </select>
</mapper>

测试类:

import com.alibaba.fastjson.JSONObject;
import com.socialsecurity.dao.AppGthdDao;
import com.socialsecurity.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DataInterchangeTest2 {
    public static void main(String[] args) throws ParseException {
        SqlSession session = SqlSessionFactoryUtil.getSession();
        AppGthdDao mapper = session.getMapper(AppGthdDao.class);
        JSONObject map = new JSONObject();
        BigDecimal aaz001B = null;
        BigDecimal aac040B = null;
        aaz001B = new BigDecimal("1");
        aac040B = new BigDecimal("1000");
        Double aac040 = aac040B.doubleValue();
        Double AAZ001 = aaz001B.doubleValue();
        Date aae030 = null;
        Date aae031 = null;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
        String date1 = "2019/2/1";
        String date2 = "2019/3/1";
        aae030 = formatter.parse(date1);
        aae031 = formatter.parse(date2);
        map.put("IS_AAE100", "2");
        map.put("IS_AAZ001", AAZ001);
        map.put("IS_AAC002", "35113");
        map.put("IS_AAE030", aae030);
        map.put("IS_AAE031", aae031);
        map.put("IS_AAC040", aac040);
        mapper.gthd(map);
        String info = (String) map.get("Os_ErrInfo");
        session.commit();
        session.close();
        System.out.println(info);
    }

}
原文地址:https://www.cnblogs.com/hoje/p/11866972.html