Spring Boot 应用程序中的错误无法从一种类型转换为另一种类型

发布于 2025-01-19 18:34:21 字数 1533 浏览 0 评论 0原文

目前我正在创建一个 Spring Boot 应用程序并收到此错误

There was an unexpected error (type=Internal Server Error, status=500).Failed to convert from type [java.util.ArrayList<?>] to type [@org.springframework.data.jpa.repository.Query java.util.List<com.example.vismameetingappwithdb.entity.Meeting>] for value '[Jono Java Meetingas]'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [@org.springframework.data.jpa.repository.Query com.example.vismameetingappwithdb.entity.Meeting]

我的存储库界面如下所示:

@ Repository
public interface MeetingRepository extends JpaRepository<Meeting,Integer>{

@ Query("SELECT nameOfMeeting FROM Meeting WHERE responsiblePerson =?1 ")
List<Meeting> findAllByResponsiblePerson(String responsiblePerson);
}

我的 RestController 类如下所示:

@ RestController
public class MeetingController {

private MeetingService meetingService;

@ Autowired
public MeetingController(MeetingService meetingService){
this.meetingService = meetingService;
}

@ GetMapping("/getmeetings")
public List<Meeting> findAll (){
return meetingService.findAll();
}

@ GetMapping("/responsibleperson/{responsiblePerson}")
public List<Meeting> findAllByResponsiblePerson(@PathVariable String responsiblePerson) {
return meetingService.findAllByResponsiblePerson(responsiblePerson);
}
}

以前有人遇到过这样的问题吗?有人可以帮忙吗?我正在尝试使用负责人端点。

Currently I am creating a Spring Boot application and getting this error

There was an unexpected error (type=Internal Server Error, status=500).Failed to convert from type [java.util.ArrayList<?>] to type [@org.springframework.data.jpa.repository.Query java.util.List<com.example.vismameetingappwithdb.entity.Meeting>] for value '[Jono Java Meetingas]'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [@org.springframework.data.jpa.repository.Query com.example.vismameetingappwithdb.entity.Meeting]

My repository interface looks like this:

@ Repository
public interface MeetingRepository extends JpaRepository<Meeting,Integer>{

@ Query("SELECT nameOfMeeting FROM Meeting WHERE responsiblePerson =?1 ")
List<Meeting> findAllByResponsiblePerson(String responsiblePerson);
}

My RestController class looks like this:

@ RestController
public class MeetingController {

private MeetingService meetingService;

@ Autowired
public MeetingController(MeetingService meetingService){
this.meetingService = meetingService;
}

@ GetMapping("/getmeetings")
public List<Meeting> findAll (){
return meetingService.findAll();
}

@ GetMapping("/responsibleperson/{responsiblePerson}")
public List<Meeting> findAllByResponsiblePerson(@PathVariable String responsiblePerson) {
return meetingService.findAllByResponsiblePerson(responsiblePerson);
}
}

Has anyone encountered such problem before? Can anyone help? I am trying to use responsibleperson endpoint.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神魇的王 2025-01-26 18:34:21

重点看你的代码

@ Query("SELECT nameOfMeeting FROM Meeting WHERE responsiblePerson =?1 ")
List<Meeting> findAllByResponsiblePerson(String responsiblePerson);
}
  • SQL查询获取nameOfMeeting的列表,它是List
  • 方法返回Meeting列表,即List

因此,不匹配会导致错误。

Focus at your code

@ Query("SELECT nameOfMeeting FROM Meeting WHERE responsiblePerson =?1 ")
List<Meeting> findAllByResponsiblePerson(String responsiblePerson);
}
  • SQL query get list of nameOfMeeting, it is List<String>.
  • Method returns list of Meeting, it is List<Meeting>.

Thefore the mismatching causes error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文