Я изучаю загрузку Spring и делаю проект с 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;
}
}
И контроллер:
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);
}
}
Что может быть причиной этого?Может ли кто-нибудь пролить свет на это ??