JPA更新操作手写SQL 传入vo或者dto对象

1.JPA手写sql进行更新操作(解析实体类)
  1. 添加注解
@Modifying
@Transactional
  1. 开启原生sql,nativeQuery = true
接口参数添加@Param注解指定别名
编写sql语句 :#{#userInDto.userName} 数据绑定占位使用 :#{#实体类.属性}
/* 手写sql进行更新用户操作 */
@Modifying
@Transactional
@Query(nativeQuery = true,value = "update my_user set user_name=:#{#userInDto.userName},age=:#{#userInDto.age},email=:#{#userInDto.email},sex=:#{#userInDto.sex} where id=:#{#userInDto.id}")
int updateMyUser(@Param("userInDto") MyUserInDto userInDto);
 
posted @ 2022-07-07 17:54  Feiyu·Thomas  阅读(87)  评论(0)    收藏  举报