Modifying 註解和事務

2021-08-14 09:03:53 字數 804 閱讀 8176

@modifying

@query("update person p set p.email = :email where id = :id")

void updateperson(@param("email") string email, @param("id") integer id)

;

ps :方法的返回值應該時int ,表示更新語句所影響的行數,在呼叫的地方必須新增事務 ,否則無法正常執行

base-package="com.atgugui.springdata">

context:component-scan>

定義的方法(personrepsotory 的實現介面中)

@modifying

@query("update person p set p.email = :email where id = :id")

int updateperson(@param("email") string email, @param("id") integer id)

;

業務層中

@service

public

class

personservice

@transactional

public

void

updatetest(string email, integer id)

}

annotation方式的事務註解和bean配置

1 2 3 context component scanbase package com context exclude filtertype annotation expression org.springframework.stereotype.controller 而在springmvc配置檔...

spring事務註解

transactional只能被應用到public方法上,對於其它非public的方法,如果標記了 transactional也不會報錯,但方法沒有事務功能.spring使用宣告式事務處理,預設情況下,如果被註解的資料庫操作方法中發生了unchecked異常,所有的資料庫操作將rollback 如果...

spring 事務註解

spring 事務註解 預設遇到throw new runtimeexception 會回滾 需要捕獲的throw new exception 不會回滾 指定回滾 transactional rollbackfor exception.class public void methodname 指定不...