使用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) 自动清除实体里保存的数据。 |
使用JPA中@Query 注解实现update 操作
猜你喜欢
转载自blog.csdn.net/harry5508/article/details/81034835
今日推荐
周排行