SpringMVC当中的 @Transactional(readOnly = true) 的作用

本文介绍了Spring框架中readOnly属性的作用及应用场景。当设置为true时,表明该方法或类仅用于读取数据,Spring将对其进行优化;反之则表示涉及数据的增删改操作。此属性的应用有助于提升性能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

readOnly=true表明所注解的方法或类只是读取数据。
readOnly=false表明所注解的方法或类是增加,删除,修改数据。

如果设置为true,spring会对其优化,可以用来提高性能。
readOnly为true 时读取的数据如果缓存中存在就从缓存中读取 这是没有问题的

readOnly为false 时读取的数据就不能从缓存中读取了 

Spring Doc里的描述。

Read-only status: A read-only transaction can be used when your code
reads but does not modify data. Read-only transactions can be a useful
optimization in some cases, such as when you are using Hibernate.

转载于:https://my.oschina.net/zjllovecode/blog/1589332

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值