首页 > 解决方案 > 如何在 Spring Boot 中从 JdbcTemplate 在 psql 中执行更新查询后获取新的更新行

问题描述

我想更新有限的行集,然后获取更新的行。我需要这是一个原子调用,因为多个服务器可以执行相同的请求并且我不想返回重复的值。

我该怎么做呢?

我已经尝试过了,但它不起作用。

    @Modifying
    @Transactional
    @Query(
        "update dto s set s.status=:status, s.agent_Id=:agentId where id in (select d.id from dto d where d.status=:pendingStatus limit 100)",
        nativeQuery = true
    )
    fun assignToAgentAndGetDtos(
        @Param("status") status: Int = 1
        @Param("agentId") agentId: String,
        @Param("pendingStatus") pendingStatus: Int = 0
    ): List<Dto>

jdbcTemplate.update只返回一个int. 我需要更新的行。

标签: postgresqlspring-bootjdbc

解决方案


推荐阅读