mybatis调用存储过程

例子一:

void canCustomerSubscribe(Map<String,Object> params);

<select id="canCustomerSubscribe" parameterType="java.util.HashMap" statementType="CALLABLE">
    CALL wallet.pkg_wallet_validation.can_customer_subscribe(
    #{msisdn, jdbcType=VARCHAR, javaType=java.lang.String, mode=IN},
    #{responseCode,jdbcType=NUMERIC, javaType=java.lang.Integer, mode=OUT})</select>

public void subscribe(String msisdn) throws InvalidArgumentException {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("msisdn", msisdn);
    params.put("responseCode", null);
    subscriberMapper.canCustomerSubscribe(params);
    System.out.println(params.get("responseCode"));}


例子二:

public interface ProductMapper{
    @Select("exec Pup_ProductSearch_Sel #{searchString}, #{pageNum}, #{pageSize}, #{totalRows,mode=OUT,jdbcType=NUMERIC}")
    @Options(statementType = StatementType.CALLABLE)
    public List<Map<String, Object>> productSearch(ProductSearchParameters params);


    public class ProductSearchParameters
    {
        private String searchString = null;
        private Integer pageNum = 1;
        private Integer pageSize = 5;
        private Integer totalRows = -1;

        // Accessors go here...
    }}
@Servicepublic class TestService{
    @Resource
    private ProductMapper mapper;


    public void run()
    {
        final ProductMapper.ProductSearchParameters params = new ProductMapper.ProductSearchParameters();
        params.setSearchString("book"); // IN parameter
        final List<Map<String, Object>> results = mapper.productSearch(params);

        for(final Map<String, Object> product : results)
        {
            System.out.println(product.get("title"));
        }

        System.out.println("Total results: " + params.getTotalRows()); // OUT parameter
    }}

参考地址:http://stackoverflow.com/questions/7817185/cannot-receive-out-parameter-from-oracle-procedure-executed-by-mybatis

http://stackoverflow.com/questions/9215784/java-mybatis-stored-procedure-call-with-out-parameters


你可能感兴趣的:(mybatis调用存储过程)