Spring data Jpa修改操作

Jpa进行update操作的方式:

1.save操作:

先通过查询方法找到要修改的实例,然后通过setXXX对属性进行修改,最后进行save操作。

 //根据输入指令流水号查询未完成的操作
 InstInput instInput = instInputRepository.findByInputNo(Long.valueOf(inputNo));
 log.info("AccountCommandService-----【inputNo】:{} 修改【指令输入】申请状态-----", inputNo);

 if ("0".equals(status)) {               //开户待审核
        instInput.setApplyStatus(InstInputApplyStatus.InputAs000.getCode());
        instInputRepository.save(instInput);
 } 

2.@Modifying + @Query注解里写JPQL语句

关于JPQL语句的详解参考该链接:https://blog.csdn.net/dtttyc/article/details/80001826

@Modifying
@Query("update useraccount set password = :password,firstName = :firstName,"
			+ "lastName = :lastName,timezone = :timezone,alertEmail=:alertEmail,"
			+ "alertMobile = :alertMobile,updateDate = :updateDate,unitId = :unitId,groupId = :groupId where id = :id")
void updateUser(@Param("password")String password,@Param("firstName")String firstName,@Param("lastName")String lastName,
			@Param("timezone")String timezone,@Param("alertEmail")String alertEmail,@Param("alertMobile")String alertMobile,
			@Param("updateDate")Date updateDate,@Param("unitId")Long unitId,@Param("groupId")Long groupId,@Param("id")Long id);

@Modifying + @Query表示进行update或delete操作,JPQL不支持insert操作

你可能感兴趣的:(Frame)