JPA更新部分字段的注解方法(动态HQL)

@Modifying(clearAutomatically = true)
	@Transactional(rollbackFor = Exception.class)
	@Query(value = "UPDATE user u set " +
			"u.weixin_name = CASE WHEN :#{#user.weixinName} IS NULL THEN u.weixin_name ELSE :#{#user.weixinName} END," +
			"u.weixin_account = CASE WHEN :#{#user.weixinAccount} IS NULL THEN u.weixin_account ELSE :#{#user.weixinAccount} END," +
			"u.level = CASE WHEN :#{#user.level} IS NULL THEN u.level ELSE :#{#user.level} END," +
			"u.send_count = CASE WHEN :#{#user.sendCount} IS NULL THEN u.send_count ELSE :#{#user.sendCount} END," +
			"u.receive_count = CASE WHEN :#{#user.receiveCount} IS NULL THEN u.receive_count ELSE :#{#user.receiveCount} END," +
			"u.user_money = CASE WHEN :#{#user.userMoney} IS NULL THEN u.user_money ELSE :#{#user.userMoney} END," +
			"u.break_count = CASE WHEN :#{#user.breakCount} IS NULL THEN u.break_count ELSE :#{#user.breakCount} END," +
			"u.created = CASE WHEN :#{#user.created} IS NULL THEN u.created ELSE :#{#user.created} END " +
			"where u.id = :#{#user.id} " , nativeQuery = true)
	int update(@Param("user")User user);

猜你喜欢

转载自blog.csdn.net/qq_42046342/article/details/89023125