我收到此错误...
无法转换类型' java.lang.String'的属性值要求的类型' java.util.Date'对于属性' start_time'
请帮我解决这个问题。
controller.java
package com.rsmagsys.rs.registration.doctorSchedule;
import java.util.Locale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.rsmagsys.rs.Utility.JsonResponse;
import com.rsmagsys.rs.registration.model.StaffScheduleForm;
import lombok.extern.slf4j.Slf4j;
@Controller
public class DoctorScheduleController {
@Autowired
private DAODoctorScheduleForm dao;
@RequestMapping(value = "registration/doctor-schedule", method = RequestMethod.GET)
public String registerInPatient(Locale locale, Model model) {
return "registration/doctorSchedule/doctorScheduleListing";
}
@RequestMapping(value = "registration/doctor-schedule/save", method = RequestMethod.POST)
public @ResponseBody JsonResponse save(Model model, StaffScheduleForm ssf) {
JsonResponse jr = new JsonResponse();
try {
StaffScheduleForm staffSchedule = dao.saveDataDoctorSchedule (ssf);
jr.setStatus("success");
jr.setResult(staffSchedule);
} catch (RuntimeException e){
e.printStackTrace();
jr.setStatus("error");
}
return jr;
}
}
DAOForm.java
package com.rsmagsys.rs.registration.doctorSchedule;
import java.util.Date;
import javax.sql.DataSource;
import org.jfree.util.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import com.rsmagsys.rs.registration.model.StaffScheduleForm;
import com.rsmagsys.rs.registration.outpatient.DAORegOutPatientForm;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Repository
public class DAODoctorScheduleForm {
@Autowired
private JdbcTemplate jdbcTemplate;
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
public StaffScheduleForm saveDataDoctorSchedule(StaffScheduleForm ssf){
Date start_time = this.jdbcTemplate.queryForObject(
"SELECT to_char(nextval('rsmagsys.seq_start'))",Date.class);
Date end_time = this.jdbcTemplate.queryForObject(
"SELECT to_char(nextval('rsmagsys.seq_end'))",Date.class);
log.info("start_time" + start_time);
log.info("end_time" + end_time);
ssf.setStart_time(start_time);
ssf.setEnd_time(end_time);
this.jdbcTemplate.update(
"insert into rsmagsys.staff_schedule(start_time, end_time) values(?,?)",
ssf.getStart_time(), ssf.getEnd_time()
);
return ssf;
}
}
javascript.jsp
$.ajax({url : '${pageContext.request.contextPath}/registration/out-patient/save',
type : 'POST',
data : {
id_no : id_no,
name : name,
dob : dob,
visit_date_time : visit_date_time
},
success : function(data) {
toastr.success("Record save successfully!");
var patient_id = data.result.patient_id;
var mrn_no = data.result.mrn_no;
var episode_id = data.result.episode_id;
var que_no = data.result.que_no;
var name_upper = data.result.name;
console.log(name_upper);
console.log(patient_id);
console.log(mrn_no);
console.log(episode_id);
console.log(que_no);
document.getElementById("patient_name").value = name_upper;
document.getElementById("patient_id").value = patient_id;
document.getElementById("mrn_no").value = mrn_no;
document.getElementById("episode_id").value = episode_id;
document.getElementById("que_no").value = que_no;
},
failure : function(data) {
toastr
.error("There's an error while saving your record.");
}
});
HTML
<!-- Modal -->
<div id="doctorSchedulePopup" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title" style="color:white;">Create Doctor Schedule</h4>
</div>
<div class="modal-body">
<form class="form-horizontal">
<div class="form-group">
<label class="col-md-3 control-label-popup">Department</label>
<div class="col-sm-4">
<select class="form-control" id="department">
<option>Please Select</option>
</select>
<span id="department_error" class="error" style="display: none">*Department Is Required</span>
</div>
<label class="col-md-2 control-label-popup">Date Start</label>
<div class="col-sm-3">
<div class="input-group">
<span class="input-group-addon">
<span class="fa fa-calendar"></span>
</span>
<input type="text" class="form-control datepicker" value="2015-11-01" id="date_start" onSelect="">
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label-popup">
<a href="#" data-toggle="modal" data-target="#">Doctor Name</a>
</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="doctor_name">
<span id="doctor_name_error" class="error" style="display: none">*Doctor Name Is Required</span>
</div>
<label class="col-md-2 control-label-popup">Date End</label>
<div class="col-sm-3">
<div class="input-group">
<span class="input-group-addon">
<span class="fa fa-calendar"></span>
</span>
<input type="text" class="form-control datepicker" value="2015-11-01" id="date_end" onSelect="">
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label-popup"></label>
<div class="col-sm-3"></div>
<div class="form-group">
<label class="col-md-3 control-label text-left">Time Start/End</label>
<div class="col-md-2">
<input type="text" class="form-control" id="start_time"/>
<span class="help-block"></span>
<span id="start_time_error" class="error" style="display: none">*Time Start Is Required</span>
</div>
<div class="col-md-2">
<input type="text" class="form-control" id="end_time"/>
<span class="help-block"></span>
hh:mm
<span id="end_time_error" class="error" style="display: none">*Time End Is Required</span>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label-popup">
</label>
<div class="col-sm-4">
</div>
<label class="col-md-2 control-label text-left">New Schedule Date</label>
<div class="col-sm-3">
<div class="input-group">
<span class="input-group-addon">
<span class="fa fa-calendar"></span>
</span>
<input type="text" class="form-control datepicker" value="2015-11-01" id="schedule_date" onSelect="">
<span id="schedule_date_error" class="error" style="display: none">*Schedule Date Is Required</span>
</div>
</div>
</div>
</form>
<div class="panel panel-default">
<div class="panel-body">
<button class="btn btn-primary pullleft">Add</button>
<button class="btn btn-primary pullleft">Remove</button>
<button class="btn btn-primary pull-right" onclick="save()">Create Schedule</button>
<button class="btn btn-primary pull-right">Copy from Selected Date</button>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" style="background-color:#5F9EA0;color:white;">Selected records pending
creation..</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<div class="table-responsive" style="margin-top: 10px;">
<table class="table table-striped table-hover table-bordered">
<thead>
<tr class="success">
<th class="text-center"></th>
<th class="text-center"></th>
<th class="text-center">Date</th>
<th class="text-center">Staff ID</th>
<th class="text-center">Doctor Name</th>
<th class="text-center">Time Start</th>
<th class="text-center">Time End</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td class="text-center"> <input type="checkbox" class="icheckbox" value=""></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
在类saveDataDoctorSchedule
的方法DAOForm.java
的前两行中,您有查询使用to_char()
将给定列的值转换为varchar2,但您将其值分配给{{1对象。
详细了解to_char():https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions180.htm
TO_CHAR(datetime)将日期时间或间隔值DATE,TIMESTAMP,TIMESTAMP WITH TIME ZONE或TIMESTAMP WITH LOCAL TIME ZONE数据类型转换为值VARCHAR2数据类型