我收到以下错误:
The method setDob(Date) in the type Employee is not applicable for the arguments (Date)
Employee类定义如下:
public class Employee {
@Column(name="DOB",nullable=false,unique=false)
private Date dob;
public Date getDob() {
return dob;
}
public void setDob(Date date) {
this.dob = date;
}
}
以下控制器代码中引发错误:
@Controller
public class EmployeeController {
@RequestMapping(value = "employees/save-employee.htm")
public String saveEmployee(HttpServletRequest request,Locale locale, Model model){
Employee employee = new Employee();
employee.setDob(Date.parseDate(request.getParameter("DOB"))); //Error raised here...
}
}
我不知道为什么我会收到此错误,尤其是该参数的类型为Date并且我将Date传递给它。
有人可以帮助我,告诉我这里做错了吗?
感谢您的时间
============================= 解决问题:
感谢大家的帮助,我能够通过将以下代码应用于控制器类来解决问题:
String dobDate = request.getParameter("DOB");
SimpleDateFormat parseDate = new SimpleDateFormat("MM/dd/yyyy");
Date dobFDate;
try {
dobFDate = (Date)parseDate.parse(dobDate);
employee.setDob(dobFDate);
} catch (ParseException e) {
e.printStackTrace();
}
我使用过两次导入:
import java.util.Date;
import java.text.SimpleDateFormat;