将MyBatis与Oracle XMLType函数"existsNode()"一起使用时,

问题描述:

我有以下情况. 这是我的mybatis sql语句:

i have following situation. this is my mybatis sql statement:

<select id="select" parameterType="String" resultMap="urlList">
    select 
                x.t002_id
    from
                 t002_metadata x  
    where
        existsNode(x.t002_xml, ?) = 1;
</select>

因此,当我从包装类中调用select方法并使用xpath表达式设置字符串参数时,将显示以下错误消息:

so when i'm calling the select method from the wrapper class and set the string parameter with a xpath expression, the following error message shows up:

Missing IN or OUT parameter at index:: 1

mybatis是否不可能使用oracle中的existNode方法编写准备好的语句?

Is it not possible for mybatis to make a prepared statement with existNode method from oracle??

提前谢谢!

有可能.您不应该编码吗?到您的MyBatis xml中. MyBatis对于动态sql具有特殊的语言,建议您阅读

It is possible. You shouldn't code the ? into your MyBatis xml. MyBatis has special language for dynamic sql, I suggest reading the MyBatis 3 User Guide.

更改您的sql映射,

<select id="select" parameterType="String" resultMap="urlList">
    select 
                x.t002_id
    from
                 t002_metadata x  
    where
        existsNode(x.t002_xml, #{id}) = 1;
</select>

它可能不是#{id},这取决于您如何调用Mybatis中的select.例如,您可能正在使用@Param标记.

It might not be #{id}, it depends on how you call select from Mybatis. For example, you might be using the @Param tag.