Spring 中的错误引导应用程序无法从一种类型转换为另一种类型
Error in Spring Boot application failed to convert from one type to another
目前我正在创建 Spring 引导应用程序并收到此错误
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 class 看起来像这样:
@ 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);
}
}
有没有人遇到过这样的问题?谁能帮忙?我正在尝试使用负责人端点。
专注于您的代码
@ Query("SELECT nameOfMeeting FROM Meeting WHERE responsiblePerson =?1 ")
List<Meeting> findAllByResponsiblePerson(String responsiblePerson);
}
- SQL查询得到
nameOfMeeting
的列表,是List<String>
.
- 方法returns列表
Meeting
,即List<Meeting>
。
因此不匹配会导致错误。
目前我正在创建 Spring 引导应用程序并收到此错误
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 class 看起来像这样:
@ 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);
}
}
有没有人遇到过这样的问题?谁能帮忙?我正在尝试使用负责人端点。
专注于您的代码
@ Query("SELECT nameOfMeeting FROM Meeting WHERE responsiblePerson =?1 ")
List<Meeting> findAllByResponsiblePerson(String responsiblePerson);
}
- SQL查询得到
nameOfMeeting
的列表,是List<String>
. - 方法returns列表
Meeting
,即List<Meeting>
。
因此不匹配会导致错误。