MyBatis SelectProvide传递对象作为参数

时间:2016-04-29 04:52:29

标签: java mybatis ibatis spring-mybatis mybatis-generator

我正在使用SelectProvider在运行时执行存储过程。

@SelectProvider(type = SqlGenerator.class, method = "getProcedure")
@Options(statementType = StatementType.CALLABLE)
public void executeProc(@Param("object") Object object);

但这会产生以下错误

  

SEVERE:Servlet [web]的Servlet.service()在路径[/ web]的上下文中引发异常[请求处理失败;嵌套异常是org.mybatis.spring.MyBatisSystemException:嵌套异常是org.apache.ibatis.binding.BindingException:找不到参数'searchString'。可用参数是[param1,object]]的根本原因   org.apache.ibatis.binding.BindingException:找不到参数'searchString'。可用参数是[param1,object]

'search String'是Search对象中的一个变量,它传递给方法。当我使用@Select直接调用存储过程时,这工作正常。

@Select(value = "{call ALL_SEARCH.SEARCH(
        #{searchString, mode=IN}, 
        #{searchType, mode=IN}, 
        #{personList, mode=OUT, jdbcType=ARRAY, jdbcTypeName=PERSON_TB, typeHandler=com.xyz.PersonArrayHandler}, 
        #{returnCode, mode=OUT, jdbcType=INTEGER}, 
        #{returnMsg, mode=OUT, jdbcType=VARCHAR})}")
@Options(statementType = StatementType.CALLABLE)
public void performSearch(Object search);

任何帮助都非常明显。

添加getProcedure方法

public static String getProcedure(Map<String, Object> params) throws ConnectorException {
    String sql = "{call ALL_SEARCH.SEARCH(" 
        + "#{searchString, mode=IN}, " 
        + "#{searchType, mode=IN}, " 
        + "#{personList, mode=OUT, jdbcType=ARRAY, jdbcTypeName=PERSON_TB, typeHandler=com.xyz.PersonArrayHandler}, " 
        + "#{returnCode, mode=OUT, jdbcType=INTEGER}, " 
        + "#{returnMsg, mode=OUT, jdbcType=VARCHAR})};"
    return sql;
}

0 个答案:

没有答案