1

在我的映射 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类型。

我的映射器界面是这样的:

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);

即使有给定日期的记录,这也会返回空列表。

有小费吗 ?

4

1 回答 1

1

像这样更改您的映射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>
于 2012-08-09T11:03:28.303 回答