我使用的是spring-mybatis,我使用的是update。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.test.Article">
<update resultType="java.lang.Long" id="updateClickCount" flushCache="true">
UPDATE "article"
SET "click_count" = "click_count" + 1
WHERE "id" = #{id,jdbcType=NUMERIC}
RETURNING "click_count";
</update>
</mapper>我希望能够在与increment count相同的请求中读取count。
相反,它给出了这个错误:
Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 81; Attribute "resultType" must be declared for element type "update".如何读取postgrsql和mybatis中的更新计数值?
发布于 2020-05-30 19:30:42
我相信UPDATE...RETURNING语句会在ResultSet中返回值。MyBatis只对<select>语句中的ResultSets进行解码。因此,您需要将语句编写为<select>。这看起来会很奇怪,但会工作得很好。不同的XML标记不进行任何检查,以确保所包含的SQL实际上与该标记匹配。
您需要考虑的另一件事是,MyBatis不会自动提交<select>语句-因此,您可能需要在语句执行后手动提交,这取决于您设置事务管理器的方式。
https://stackoverflow.com/questions/62074954
复制相似问题