[英]MyBatis : query java.util.Date with DATE type on MYSQL database
在我的Mapping XML中,我有:
<select id="getPatientsByBirthday" parameterType="date" resultType="com.axiohelix.nozoki.entity.Patient">
SELECT id AS id,
pharumo_id AS pharumoId,
code AS code,
family_name AS familyName,
first_name AS firstName,
family_name_kana AS familyNameKana,
first_name_kana AS firstNameKana,
gender AS gender,
address AS address,
tel AS tel
FROM tbl_patient
WHERE birthday = #{id}
</select>
其中,生日是MYSQL数据库中的DATE类型。
我的Mapper界面是这样的:
public interface PatientMapper {
void insertPatient(Patient patient);
Patient getPatientById(Integer id);
Integer getPatientCount();
List<Patient> getPatientsByBirthday(Date bday);
}
我试图查询特定生日的患者:
Calendar cal1 = new GregorianCalendar(1980, 8, 15);
Date bday=cal1.getTime();
List<Patient> plist=mapper.getPatientsByBirthday(bday);
即使有给定日期的记录,此返回空列表。
有小费吗 ?
像这样更改您的映射xml;
<select id="getPatientsByBirthday" parameterType="java.util.Date" resultType="com.axiohelix.nozoki.entity.Patient">
SELECT id AS id,
pharumo_id AS pharumoId,
code AS code,
family_name AS familyName,
first_name AS firstName,
family_name_kana AS familyNameKana,
first_name_kana AS firstNameKana,
gender AS gender,
address AS address,
tel AS tel
FROM tbl_patient
WHERE birthday = #{date}
</select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.