gpt4 book ai didi

java - 无法克服这个 org.springframework.dao.dataaccessException

转载 作者:太空宇宙 更新时间:2023-11-04 10:25:26 25 4
gpt4 key购买 nike

我正在学习 Spring boot,并且正在做一个使用 jdbcTemplate 执行 CRUD 操作的项目。每当我在查询中引入 getObject() 参数时,都会出现异常。 IDE建议添加异常或者用try catch包围;两者都会导致错误

"Incompatible types 
Expected: java.lang.throwable
Found:org.springframework.dao.dataaccessexception"

这是我的服务方法:

import com.vaidiksanatansewa.gurusewa.model.Appointment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class AppointmentService {

private JdbcTemplate jdbcTemplate;


public void add(Appointment appointment) throws DataAccessException {
jdbcTemplate.update("insert into appointment(name, address, contact,
sewa_fid, guru_fid,date,
hour , status, created_date, updated_date)
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
appointment.getName(),appointment.getAddress(),appointment.getPhone(),
appointment.getSewa_fid(),appointment.getGuru_fid(),
appointment.getDate(), appointment.getHour(),appointment.getStatus(),
appointment.getCreated_date(),appointment.getUpdated_date());

}

        }

这是模型:

package com.vaidiksanatansewa.gurusewa.model;

import java.util.Date;


public class Appointment {
Long id;
String name;
String address;
String phone;
Integer sewa_fid;
Integer guru_fid;
Date date;
Integer hour;
Integer status;
Date created_date;
Date updated_date;

public Appointment() {
}

public Appointment(Long id, String name, String address, String phone, Integer sewa_fid, Integer guru_fid, Date date, Integer hour, Integer status, Date created_date, Date updated_date) {
this.id = id;
this.name = name;
this.address = address;
this.phone = phone;
this.sewa_fid = sewa_fid;
this.guru_fid = guru_fid;
this.date = date;
this.hour = hour;
this.status = status;
this.created_date = created_date;
this.updated_date = updated_date;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

public Integer getSewa_fid() {
return sewa_fid;
}

public void setSewa_fid(Integer sewa_fid) {
this.sewa_fid = sewa_fid;
}

public Integer getGuru_fid() {
return guru_fid;
}

public void setGuru_fid(Integer guru_fid) {
this.guru_fid = guru_fid;
}

public Date getDate() {
return date;
}

public void setDate(Date date) {
this.date = date;
}

public Integer getHour() {
return hour;
}

public void setHour(Integer hour) {
this.hour = hour;
}

public Integer getStatus() {
return status;
}

public void setStatus(Integer status) {
this.status = status;
}

public Date getCreated_date() {
return created_date;
}

public void setCreated_date(Date created_date) {
this.created_date = created_date;
}

public Date getUpdated_date() {
return updated_date;
}

public void setUpdated_date(Date updated_date) {
this.updated_date = updated_date;
}
}

Controller :

package com.vaidiksanatansewa.gurusewa.controller;

import com.vaidiksanatansewa.gurusewa.model.Appointment;
import com.vaidiksanatansewa.gurusewa.service.AppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class AppointmentController {

@Autowired
AppointmentService appointmentService;

@RequestMapping("/Appointment")
public List<Appointment> getAll() {

return appointmentService.getAll();
}

@RequestMapping("/Appointment/{id}")
public Appointment getById(@PathVariable Long id) {

return appointmentService.getById(id);
}

@RequestMapping(method = RequestMethod.POST, value= "/student")
public void add(@RequestBody Appointment Appointment) {
appointmentService.add(Appointment);

}

@RequestMapping(method = RequestMethod.PUT, value= "/student/{id}")
public void markAsAccepted(@RequestBody Appointment Appointment,@PathVariable Long id){
appointmentService.markAsAccepted(id,Appointment);
}



}

请问是什么原因造成的呢?有人能解释一下吗?

最佳答案

这个错误很奇怪,可能是某个项目状态不佳。尝试构建项目(maven 构建或安装)并验证编译后的 war 中错误是否仍然存在(并且是相同的)。

关于java - 无法克服这个 org.springframework.dao.dataaccessException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50583092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com