postgresql - 如何在 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
. 我需要更新的行。
解决方案
推荐阅读
- maven - 如何运行 Spring Boot 应用程序
- html - 将按钮与输入对齐
- coldfusion - 如何在 Mura 中调用 $.dspBody() 函数而不实际显示内容?
- python-2.7 - Selenium / Chrome 中的所有域都有 delete_all_cookies() 吗?
- amazon-web-services - AWS Cloudformation - 在 YAML 文件中导入 Jinja 定义的变量
- javascript - Vue 将对象作为计算属性传播
- xml - 将标签内的内容与标签外的内容分开
- protractor - 使用 Appium 和 Protractor 测试移动设备时如何启动 Chromedriver
- javascript - 选择单选按钮时,如何测试是否已经选择了另一个?
- python - python - 如何使用顺序遍历比较树