如何在myBatis xml映射器中调用postgres函数?

时间:2019-08-06 08:29:47

标签: postgresql function mybatis

如何使用xml在myBatis中调用函数?

我有这个功能

CREATE OR REPLACE FUNCTION save_audit_deletions(IN days numeric, IN 
table_name text) 
RETURNS void AS
$body$
DECLARE
   interval INT;
BEGIN

    UPDATE table_name SET backup = 1 WHERE backup = 0 AND creationdate >= now()::DATE - days AND creationdate < now()::DATE;

    IF copy_func(table_name, days) > 0 THEN
    DELETE FROM table_name WHERE backup = 1;
    ELSE
    UPDATE table_name SET backup = 0 WHERE backup = 1;
    END IF;
END
$body$
LANGUAGE plpgsql;

如何调用此函数传递参数?谢谢。

1 个答案:

答案 0 :(得分:1)

XML语句和Java映射器方法如下所示。

<update id="saveAuditDeletions" statementType="CALLABLE">
  {call save_audit_deletions(#{days}, #{text})}
</update>
void saveAuditDeletions(@Param("days") Integer days, @Param("text") String text);

仅供参考,无需XML即可完成。

@Options(statementType = StatementType.CALLABLE)
@Update("{call save_audit_deletions(#{days}, #{text})}")
void saveAuditDeletions(@Param("days") Integer days, @Param("text") String text);