java - 更新 Spring 存储库的最佳实践
问题描述
我有如下所示的 Spring Repo 类:
@Repository
public interface EmployeeRepository
extends CrudRepository<Employee, Long> {
@Query("Select s from Employee s where s.Id = ?1")
Optional<Employee> findEmployeeByID(String Id);
@Transactional
@Modifying
@Query(" How to DO that")
UpdateEmployeeDetails()
}
如何有效地更新员工详细信息,因为员工表包含超过 15 个字段我无法为每个字段编写函数,我们如何生成具有通用逻辑的查询来更新
例如:如果我们只想更新名称,那么UpdateEmployeeDetails()
将执行此查询:
UPDATE Employee SET firstName=UPPER(firstName) WHERE id in :ids
如果我们要更新名称和地址:
UPDATE Employee SET firstName=UPPER(firstName), Address = "Address" WHERE id in :ids
我们如何有效地做到这一点,因为有可能的字段,所以我们想动态生成查询
解决方案
推荐阅读
- c++ - 在文件上实现迭代器
- python - 如果循环中没有提供输入(或按下回车键),如何在 python 中结束无限循环
- javascript - 如何为其他组件道具重用组件内的函数类型
- javascript - React 不会映射对象数组,TypeError: data.map is not a function
- django - 来自 Django 模型/AdminModel 的 Wagtail 页面
- powershell - 是否可以使用 with 和 endwith 指令?
- xamarin.forms - Xamarin.Forms 按钮在滚动视图 (iOS) 中不起作用
- c# - 实体框架从数据库中获取完整的对象树
- angular - 从列表拖放到放置区域
- laravel - 页面在共享主机托管的 laravel 网站中立即过期