Spring Boot 应用程序中的错误无法从一种类型转换为另一种类型
目前我正在创建一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
重点看你的代码
nameOfMeeting
的列表,它是List
。Meeting
列表,即List
。因此,不匹配会导致错误。
Focus at your code
nameOfMeeting
, it isList<String>
.Meeting
, it isList<Meeting>
.Thefore the mismatching causes error.