Spring MVC应用程序语法错误 [英] Spring MVC Application syntax error

查看:88
本文介绍了Spring MVC应用程序语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个问题:

Spring MVC应用程序

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

I solved with some new code, making StudentDeleteRepository.java and StudentDeleteRepositoryImpl.java and adding the tags as a user suggested:

@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]

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentDeleteController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.github.elizabetht.service.StudentDeleteService com.github.elizabetht.controller.StudentDeleteController.studentDeleteService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentDeleteService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.github.elizabetht.repository.StudentDeleteRepository com.github.elizabetht.service.StudentDeleteServiceImpl.studentDeleteRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentDeleteRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: from near line 1, column 10 [delete s from com.github.elizabetht.model.Student s where s.userName = :userName and 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

这篇关于Spring MVC应用程序语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆