报错信息
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'taskRepository': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Using named parameters for method public abstract java.util.List sdjzu.edu.courseplatformbackend.repository.TaskRepository.findTaskByCourseIdAndState(java.lang.Integer,java.lang.String) but parameter 'Optional[state]' not found in annotated query 'select * from task where course_id = :courseId and state = : state'!
自定义Sql
public interface TaskRepository extends JpaRepository<Task,Integer> {
/*根据课程号和作业状态查找正在进行的作业*/
@Query(value = "select * from task where course_id = :courseId and state = : state",nativeQuery = true)
List<Task> findTaskByCourseIdAndState(@Param("courseId") Integer courseId,@Param("state") String state);
}
错误原因:此处多加了一个空格(改了半天)