【发布时间】:2021-02-12 16:16:53
【问题描述】:
我目前正在学习spring boot,遇到错误提示
method count(JobViewWrapper) is already defined
是的,因为它有 2 个相同的方法名,但该方法有 2 个单独的功能,第一个是计算所有带有已删除标志 1 的作业。 第二个(count-active),是统计所有已删除标志为 1 且为活动标志 1 的作业。
所以我需要这两种方法,有解决方法吗?
@PostMapping(value = "/count")
public long count(@RequestBody(required = false) JobViewWrapper wrapper) {
System.out.println("into controller count");
if (wrapper == null) {
wrapper = new JobViewWrapper();
}
System.out.println("Prepare to count service");
return JobService.countLazyView();
}
@PostMapping(value = "/count-active")
public long count(@RequestBody(required = false) JobViewWrapper wrapper) {
System.out.println("into controller count");
if (wrapper == null) {
wrapper = new JobViewWrapper();
}
System.out.println("Prepare to count service");
return JobService.countLazyViewIsActive();
}
我的服务
public long countLazyView() {
return lowonganKerjaRepo.countLazyView();
}
public long countLazyViewIsActive() {
return lowonganKerjaRepo.countLazyViewIsActive();
}
【问题讨论】:
-
改为调用第二个
countActive? -
在同一个类中不能有 2 个具有相同签名(名称 + 参数)的方法。重命名其中一个
-
Federico,我使用了 2,因为我需要 /count 来计算 repo 中的所有它们,它只有过滤“where deleted=1”,并且值 /count-active 的方法在 repo 中有查询“ where deleted=1 and is_active=1" 所以它会使计数差异记录数
-
pedrohreis,JobViewWrapper 实际上是一个类名,我试图在该方法中重命名“包装器”,如“包装器1”,但仍然出现相同的错误有什么办法解决这个问题?
标签: java spring spring-boot lazydatamodel