简体   繁体   English

如何通过MyBatis将XML字符串作为输入参数映射到存储过程?

[英]How to map an XML string as an input parameter to a stored procedure via MyBatis?

I've been working on sending an XML string as an input parameter to a SQL Server stored procedure, which is called through a MyBatis mapping interface in Java. 我一直在努力将XML字符串作为输入参数发送到SQL Server存储过程,该过程通过Java中的MyBatis映射接口调用。 My mapping is defined like so: 我的映射定义如下:

@Update(value = "{ call prcFoo(" +
                "#{ stringValue, jdbcType=VARCHAR, mode=IN }," +
                "#{ xmlValue, jdbcType=CLOB, mode=IN } ) }") 
@Options(statementType = StatementType.CALLABLE)
Integer sendXML(@Param("stringValue") String stringValue, 
                   @Param("xmlValue") String xmlValue);

The mapping returns an integer value, rather than a result set. 该映射返回一个整数值,而不是结果集。 I'm getting the procedure error condition (a negative integer) when I make a call using this mapping. 使用此映射进行调用时,出现过程错误情况(负整数)。 It appears to be a problem with reading in the XML, because when I call the procedure directly on the database with the same XML string, it returns the expected value. 读取XML似乎是一个问题,因为当我使用相同的XML字符串直接在数据库上调用该过程时,它将返回期望值。 Am I using MyBatis incorrectly, or is something else wrong? 我是错误地使用MyBatis,还是其他错误?

Have you tried using the XML data type instead of a string 您是否尝试过使用XML数据类型而不是字符串

http://technet.microsoft.com/en-US/library/ms189887(v=sql.90).aspx http://technet.microsoft.com/zh-CN/library/ms189887(v=sql.90).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM