StudentDeleteRepository

StudentDeleteRepository

我有这个问题:

Spring MVC application

我用一些新代码解决了,制作了StudentDeleteRepository.java和StudentDeleteRepositoryImpl.java并根据用户的建议添加了标签:

@Autowired
private StudentDeleteRepository studentDeleteRepository;


@Transactional
public Student delete(Student student) {
    return studentDeleteRepository.save(student);
}


StudentDeleteRepository.java给出错误:


  org.springframework.beans.factory.BeanCreationException:创建名称为'studentDeleteController'的bean时出错:自动连接依赖项的注入失败;嵌套的异常是org.springframework.beans.factory.BeanCreationException:无法自动连线字段:私有com.github.elizabetht.service.StudentDeleteService com.github.elizabetht.controller.StudentDeleteController.studentDeleteService;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为'studentDeleteService'的bean时出错:自动连接依赖项的注入失败;嵌套的异常是org.springframework.beans.factory.BeanCreationException:无法自动连线字段:私有com.github.elizabetht.repository.StudentDeleteRepository com.github.elizabetht.service.StudentDeleteServiceImpl.studentDeleteRepository;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为'studentDeleteRepository'的bean时出错:FactoryBean在对象创建时抛出了异常;嵌套异常是java.lang.IllegalArgumentException:org.hibernate.hql.internal.ast.QuerySyntaxException:意外令牌:从第1行第10列[从com.github.elizabetht.model.Student删除s,其中s.userName = :userName和s.password =:password]


这是StudentDeleteRepositoryImpl.java类:

package com.github.elizabetht.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.github.elizabetht.model.Student;

@Repository("studentDeleteRepository")
public interface StudentDeleteRepository extends JpaRepository<Student, Long> {

    @Query("delete s from Student s where s.userName = :userName and s.password = :password")
    Student deleteByLogin(@Param("userName") String userName, @Param("password") String password);

}

最佳答案

delete from Student s where s.userName = ?1 and s.password = ?2

10-04 10:41