当前位置:主页 > 软件编程 > JAVA代码 >

使用JPA中@Query 注解实现update 操作方法(必看)

时间:2021-05-30 08:46:51 | 栏目:JAVA代码 | 点击:

使用JPA中@Query 注解实现update 操作,代码如下:

@Transactional

@Modifying(clearAutomatically = true)

@Query(value = "update info p set p.status =?1 where p.id = ?2",nativeQuery = true)
 int updateStatusById( String status,  String id);

备注:

1、更新info表下指定id的status字段, 这里使用了原生的sql语句。

2、@Transactional 注解用于提交事务,若没有带上这句,会报事务异常提示。

3、@Modifying(clearAutomatically = true) 自动清除实体里保存的数据。

您可能感兴趣的文章:

相关文章